Position Controller Kit problem with negative counts
Hi
I have a Parallax Motor Mount and Wheel Kit which I am controlling with an Arduino Uno. When the position controllers are issued with positive counts via the TRVL command the motors behave as expected. I do not get any erratic behavior, so I am pretty sure the wiring is correct and the correct motor has been set to have its orientation reversed using the SREV command. However, when I issue negative counts to the TRVL command in order to rotate the motors in the negative direction, they still rotates in the positive direction... For example if I send -36 counts to the position controller in order to rotate in the negative direction, it will rotate at least 36 counts (usually quite a bit more) in the positive direction. Has anybody come across this problem before? I find it really odd that it works perfectly for positive values but not for negative values. Any pointers as to the underlying problem?
I have a Parallax Motor Mount and Wheel Kit which I am controlling with an Arduino Uno. When the position controllers are issued with positive counts via the TRVL command the motors behave as expected. I do not get any erratic behavior, so I am pretty sure the wiring is correct and the correct motor has been set to have its orientation reversed using the SREV command. However, when I issue negative counts to the TRVL command in order to rotate the motors in the negative direction, they still rotates in the positive direction... For example if I send -36 counts to the position controller in order to rotate in the negative direction, it will rotate at least 36 counts (usually quite a bit more) in the positive direction. Has anybody come across this problem before? I find it really odd that it works perfectly for positive values but not for negative values. Any pointers as to the underlying problem?
cpp
18K
Comments
Could you use a more accepted way of getting the MSB and LSB of an int here?
The way the bytes are being separated doesn't work with negative numbers.
I think this could be fixed by changing the line:
To:
-30 / 256 = 0 so the high byte is being set to zero when you really want it set to 255.
Sorry, I don't have the line number. I opened the code in note pad since my CPP editor causes my computer to slow down too much.
Let me know if you have trouble finding the appropriate line and I'll find the line number for you.
Replacing the / 256 entries with >> 8 has done the trick.
Thanks for your help!