Propeller Servo Jitter
copacetic353
Posts: 52
Hello all,
I am using the Simple Radio Control Capture and Repeat, and Servo32v7 objects off of the OBEX to capture signals and control three servos that will eventually (hopefully) be used to control the cyclic on a model helicopter.
However, I am running into an issue with servo jitter as noted in the thread title. When I control just one servo, the motion seems to be very fluid even when I move the sticks on my radio quickly but when I try to do the same with all three cyclic servos, instead of a nice fluid servo movement, it becomes jerky, very much so when I move the sticks fast.
I have tried playing with certain values within both objects but to no avail. I have also tried controlling one servo with its own cog by declaring each servo as its own object and using the Start method within Servo32v7, but I get the same issue.
Please help!
The relevant code is here:
Servo.Start
repeat
x := PULSIN(PIN_SERVO_IN_1,1)
y := PULSIN(PIN_SERVO_IN_2,1)
z := PULSIN(PIN_SERVO_IN_3,1)
Servo.Set(PIN_SERVO_OUT_1,(x * 2))
Servo.Set(PIN_SERVO_OUT_2,(y * 2))
Servo.Set(PIN_SERVO_OUT_3,(z * 2))
I am using the Simple Radio Control Capture and Repeat, and Servo32v7 objects off of the OBEX to capture signals and control three servos that will eventually (hopefully) be used to control the cyclic on a model helicopter.
However, I am running into an issue with servo jitter as noted in the thread title. When I control just one servo, the motion seems to be very fluid even when I move the sticks on my radio quickly but when I try to do the same with all three cyclic servos, instead of a nice fluid servo movement, it becomes jerky, very much so when I move the sticks fast.
I have tried playing with certain values within both objects but to no avail. I have also tried controlling one servo with its own cog by declaring each servo as its own object and using the Start method within Servo32v7, but I get the same issue.
Please help!
The relevant code is here:
Servo.Start
repeat
x := PULSIN(PIN_SERVO_IN_1,1)
y := PULSIN(PIN_SERVO_IN_2,1)
z := PULSIN(PIN_SERVO_IN_3,1)
Servo.Set(PIN_SERVO_OUT_1,(x * 2))
Servo.Set(PIN_SERVO_OUT_2,(y * 2))
Servo.Set(PIN_SERVO_OUT_3,(z * 2))
Comments
My best guess, move the PULSIN commands to a separate process. Use semaphore locks to reduce dirty x, y and z reads while invoking Servo.Set().
Something like
The power supply you are using might not provide enough power for all the servos.
You ought to try running the servos with a known program to see if they will all move.
If you run my QuickStart servo tester, any servos attached to pins 24 - 27 should start oscillating. If you're not using a QuickStart board, try to make sure nothing is connected to pins 0 - 7.
The servos are being powered by the helicopter battery, I don't think power is an issue here.
Mike,
I tried what you suggested and, perhaps I was implementing it incorrectly, but I was still getting the same issue.
I did however do this and it seems to work, but unfortunately ties up 4-5 cogs which I want to avoid if possible:
Mike,
I am very new to the Propeller and Spin.
I was really hoping you were not going to mention PASM lol.
Could I bother you to send me down the right path to getting this done in a more efficient way? I've never coded PASM and it all looks pretty complicated to me but I am willing to learn.
Thank you so much for your time!!
My PropBOE-Bot project read the input from a RC receiver and then sends pulses (after being mixed) to a pair of servos.
I've suggest you use the same receiver object I used. The "PulseIn" method is too slow for what you want to do.
First, is is really necessary? Do you need more than 2 free COGs for something else? I assume the control signal is not always going to be an RC transmitter.
I don't see where you used an object that captures a signal from the R/C RX? Capturing that signal definitely seems to be what is slowing my program down, what would be a faster method than PulseIn?
I still need to read input from an IMU and I also need COGs to control a neural network, and I do not know how many COGs that will take. Freeing up as many COGs as possible while still giving me the data I need to feed through the NN would be great! Efficiency is always a good thing
The object "RC_Receiver_6" can receive up to six channels from the RC receiver.
You need to let it know which of the first six pins to use before you call its "Start" method as I did here.
I use this method to update my array of channel values.
The constant "_RxMask" had the value (percent sign)11_1111 assigned to it. (The forum software doesn't like the percent sign used to indicate binary numbers.)
I added a bit of deadband to keep the wheels from jittering when I wanted them to be stopped.
I used the aileron and elevator channels to control the bot's two wheel speeds.
when I use the QuickStart Board with the "PE servo Object" 2007 code for continueus servo control, one servo turns just very very slighty and slowly...... just a guess.... but maybe adding a couple of Caps on the servo and/or power supply can just fix the noise problem....if it is noise.
Mike4421,
Thank you very much for your response but I don't think noise is the issue here. I believe Mike G hit the nail on the head in the reading one pulse one pin at a time using PulseIn is slowing the program down dramatically.
Mike G,
I will toy with this a little bit today to see if it is faster than the method I was using before. I just finished constructing my 3D State Object that is very simply an abstract data type and operators that will describe the state of something in 3D space. Thank you!