Quote:
|
Originally Posted by intellec7
I have attached code that *should* work. You will probably need to modify all of the Rx inputs and PWM outputs.
If any one sees a problem with this code, you are probably right . :-D
BTW there is no overflow protection, which might happen, but I am assuming you don't need really precise servo control? When you stop moving the robot the servo stops in place, but when you start moving it again, the servo moves to its positive limit and then starts the back and forth movement again.
|
Yea, there appear to be some syntactical (things written wrong) and symantical (things done wrong). The simplest thing is that the incrementing and decrementing (is that a word?) of pendu_speed dont really do what they are supposed to. Instead incrementing or decreasing you assign the value of 1 or -1 to pendu_speed. It should be pendu_speed++ or pendu_speed--.
The next problem is with this statement
pendu_servo = pendu_speed + pendu_servo
the value of pendu_servo could be 250 in one loop and the next time around, the joystick could be nuetral but because pendu_servo already has the value of 250, it will continue to be 250.
You could probably fix that by moving the code block setPwm(3, pendu_servo) into the else statement. Then change the if statement to to setPwm(3,127). That way the if the statement evaluates to true (meaning joystick is nuetral), the pwm will be dead. However, if it evaluates falsely, it will be assigned to a value.
And in terms of the actual servo movement, I cant really help because I have actually never worked with servos.
And my *corrections* of your mistakes could also be mistakes.