How to turn Servo back to 0 degree with Kinoma PWM

Hello , BrianKinoma :

We are using this servo : http://www.servodatabase.com/servo/towerpro/sg90

we can turn the servo to degree 180...but we can't turn it back!

we have tried different value from .1 ~ .9 ,

our servo is still remain at degree 180 : (

exports.rotate = function() { this.servo.write( .5 ); }

help!!!

Answers

  • I have the same problem as you do. I also try negative number, but still not work.

  • Hi folks!

    I don't have that exact servo handy to test with, but I can give you some general advice.

    The PWMs on Kinoma Create are tuned to be used for relatively high-frequency operations, such as controlling an LED or LCD backlight. (It happens that this is a characteristic of the underlying SOC that we use.) Servos and stepper motors, by contrast, are relatively low-frequency devices. The net result is that you're much better off just driving your servos directly from KinomaJS on a Digital pin rather than a PWM.

    Here's example application and BLL code for driving a Digital pin with a frequency of 20ms and a pulse width of 1500us. We'll incorporate this into a new sample for the website soon.

    script section of the main.xml

            var pwmFrequency = 20;
            var pulseWidth = 1.5;
            var repeatInterval = pwmFrequency - pulseWidth;
    
            application.invoke(new MessageWithObject("pins:configure", { 
                motor:{
                    require: "fakePWM",
                    pins:{
                        motorPWM: {pin: 4}
                    }
                }
            }));
    
            application.invoke(new MessageWithObject("pins:/motor/pulse?repeat=on&interval=" + repeatInterval, pulseWidth));
    

    BLL code (fakePWM.js)

    exports.pins = {
        motorPWM: {type: "Digital", direction: "output"}
    };
    
    exports.configure = function() {
        this.motorPWM.init();
    }
    
    exports.pulse = function(pulseWidth){
        this.motorPWM.write(1);
        sensorUtils.udelay(pulseWidth * 1000);
        this.motorPWM.write(0);
    }
    

    The details will vary for your specific servo, but basically you should start and stop the repeats while changing pulseWidth to select different angles. Your servo may also need a shorter frequency, in which case you should bump down pwmFrequency a bit (just make sure it is always greater than pulseWidth).

    Depending on your exact part, you may notice that non-continuous servos are it is a little twitchy once they complete their travel. To avoid this, just stop the repeat.

    -- Andy

  • edited April 2016

    UPDATE: There is now support for PWMs on the front panel headers. They differ from those of the back panel in important ways, notably that they can run at a much lower frequency for compatibility with servos. This will obviate the need for creating a soft/fake PWM.

    The API has been extended to work better for servos as well. As servos aren't as concerned with the duty cycle as they are with the pulse width, you may now use pulse width as a parameter with the front panel PWMs.

    To use the front panel PWMs, assign them using the Front Pins app (up to three on each header). (if the option is not available, update the Kinoma Software on the Kinoma Create.) Then configure your PWMs as usual in the code. When you write to the PWM, you may now pass two arguments. The first one is the pulse width and the second is the period, both in milliseconds. (Internally they are rounded to the nearest multiple of 0.128 milliseconds, and the maximum value for each is 32.64ms.)

    When passing a single argument, it will be (as before) interpreted as duty cycle, a value from zero to one. The PWMs on the rear header only support single-argument (duty cycle) mode, and the period is still fixed at 78.77 microseconds.

    While servos can be powered from the front pins, even at 5V, it is recommended that servos be powered from an external power supply for best results.

  • There are two ways to see the new servo-savvy PWMs in action.

    The first way is with the Pin Explorer app in the Create launcher. After assigning a front pin as PWM, the corresponding tab will have a servo mode with sliders allowing you to control the period and the pulse width. The easiest way to play with that is to lower the period to around 4ms, thereby maximizing the precision of the pulse width slider.

    The second way is to look at the revised [pwm-continuous-servo] (https://github.com/Kinoma/KPR-examples/tree/master/pwm-continuous-servo) sample application. If a front pin is assigned as a PWM, the app will now let you rotate in either direction and do a powered stop. It also shows how to implement reading from a JSON file that allows you to provide specifics about your servo (what pulse widths will drive the servo in which direction, etc.). Finally, there's a new BLL with a servo simulator that makes it easier to develop servo apps in the simulator environment. The API for the BLL is super simple and easily reusable.

Sign In or Register to comment.