joystick dampening math/ code
Owen
Posts: 100
Anyone know of any math for dampening the effect of a joystick? I am building a project that precicely and remotly controls a motion picture camera using a playstation 2 controller and a propellar chip. at the moment the playstation controller is too sensitive and needs some way of dampening the Playstation joystick input. basicly I would like to have have an adjustable control dampening similar to the dampening an electric wheel chair might have. anyone done somthing like this before?
Comments
Actual_position := (Actual_position * Smooth + Requested_position * (100 - Smooth)) / 100
Requested_position is the input from the joystick. Actual_position is the number you use instead. Smooth ranges from 0 to 100 and represents the amount of smoothing. If Smooth is zero, no smoothing takes place. if Smooth is 100, no movement takes place. You'll find a happy medium somehwere in between.
Don't overdo the smoothing, though, as the person controlling things will have a tendency to overshoot the target. In any event, it will take some practice to get used to.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 3/17/2007 2:23:09 AM GMT
Is the "Actual_position" on the right side of the equation the previous Actual_position?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
Yes. And I should have noted that it needs to be initialized to the Requested_position at the beginning of the program.
-Phil
Owen
By "change direction" are you implying that Requested_position can take on negative values? If that's the case, some major code changes will be necessary.
-Phil
Owen
-Phil
when changeSpeed is called it is sent the current position of the joystick which is one byte 127 being the center of the joystick 0 and 255 being the all all the way foward or all the way back. the joystick is then remaped so that 0 is the center and 128 and 127 are the foward and back and direction can be determined. next the joystick is remaped to a scale that the stepper motor methode can handle ( sets the delay between steps) 255000 being stoped and 1 being the fastest step rate. then the speed is smoothed by the by the IIR equation before setting the output speed(spd). I know there is likely an eeasier way to do this but I do't have much programing experience yet. thanks for the help
Owen
Post Edited (originator) : 3/18/2007 12:19:26 AM GMT
The variable requested_speed needs to be continuous at the edges of the deadzone. This will fix it so it is.
-Phil
Anyways, fascinating stuff, glad you posted as I have gained some useful info from Phils ideas.
I gave this a try but all it did was slow the speed of my motors, my dead zone still doesn't work and smoothing doesn't work for changing directions. I guess I'm still a little confused because I used (speed -127) and (speed - 128) to remap the joystick so if I set them to (speed - 121) and (speed - 133) I'm just truncating the range of the joystick right?
thanks for the help, I'm slowly getting there
owen
Okay, I see the problem. Dir is based on the instantaneous value of speed, whereas spd is smoothed. Both need to be based on smoothed values. I would compute requested_speed as a smoothed byte value from spd, forgetting about direction, but including any deadzone allowances you think are necessary. Then compute dir from requested_speed, along with a period variable for the steppers.
Strictly speaking period = k / speed, rather than k - speed, and you'll probably get better results if you follow this dictum. Of course speed can be zero, so you'll need to include a special case to avoid dividing by zero.
-Phil