Putting robotics at your service™

Free shipping on orders over $75

Servo Programming Help

Print view Share :
Previous topicNext topic

Page 2 of 2 [ 17 posts ]

1, 2
Rookie ( offline )
Posts: 23
Posted: 2011-03-15 18:47 
This is for the regional science fair tomorrow. Helllllllllllllllp!!!!

User avatar
Guru ( offline )
Posts: 4937
Posted: 2011-03-15 19:58 
I don't know from your last couple of posts what your complete code is, but here are a couple of pointers...

The array temp, was used to read in the current values of the PS2, the array indexes 3-6 are for the two joysticks. They are unsigned byte values, which implies that they have a value from 0-255. So for whatever reason you appear to be adding 255 these values so for example
lvert will always have a value from 255 to 511 so you will always be adding. You should probably do something like:
lvert = temp(6) -128

But you have an additional problem in that lver is defined as a word, which is unsigned (range 0-65535). You probably want to define it as SWORD which is signed.

Next I don't know what you do after issuing the hservo commands. Do you simply jump back up to main, which starts the next read of the PS2, calculates and reissue the HSERVO? If so suppose it can complete this loop in lets say .025 seconds. If you move the joystick up to the top and lets say you add on an average of 500 units with your current code, you have 12000/500 or 24 cycles through the loop before you hit your max value, so 24*.025 or about .6 seconds before you hit full speed. My guess is that the loop may take less time than that so you can see you hit max speed really quick.

What some do is do a pause of some time after the hservo command to give it some time to do stuff. Or when the are ready to output the next command, the do a loop to query the servos of the previous move to see if they complete the previous move...


1, 2

All times are UTC - 5 hours [ DST ]. It is currently 2015-07-28 09:19
Feedback Form