Shop OBEX P1 Docs P2 Docs Learn Events
Position Controller Kit problem with negative counts — Parallax Forums

Position Controller Kit problem with negative counts

rsummanrsumman Posts: 5
edited 2014-05-25 14:46 in Robotics
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?

Comments

  • whickerwhicker Posts: 749
    edited 2014-05-25 14:14
    I don't understand the implications of what byte( ) does
        Output_Buffer[1] = byte(In_Parameter / 256);  // high byte of the integer speed
        Output_Buffer[2] = byte(In_Parameter);        //least significant byte of integer speed
    

    Could you use a more accepted way of getting the MSB and LSB of an int here?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-25 14:30
    I think your problem is in the "Tell_Motor" function.

    The way the bytes are being separated doesn't work with negative numbers.

    I think this could be fixed by changing the line:
    Output_Buffer[1] = byte(In_Parameter / 256);  // high byte
    

    To:
    Output_Buffer[1] = byte(In_Parameter >> 8);  // high byte
    

    -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.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-25 14:34
    I noticed some other " / 256" entries. You should probably do a search for all the instances of "/ 256" to see if they should be replaced with ">> 8".
  • rsummanrsumman Posts: 5
    edited 2014-05-25 14:46
    Hi Duane

    Replacing the / 256 entries with >> 8 has done the trick.

    Thanks for your help!
Sign In or Register to comment.