Can wheel motors rotate in both directions?


#1

i’m trying to hack my GPG, and it would be helpful if it’s possible to control the rotation of the wheels, both clockwise and counter clockwise.

is this possible? if so, how?

i see commands like “left()”, “right()”, etc, that control one or both wheels. any way to control the direction of rotation?

thanks


#2

ok, just found the controls for motor rotation in the firmware, fw_ver_11.ino:

//Turn GoPiGo Left slow (one motor off, better control)
void left()
{
    digitalWrite(motor1_control_pin1, LOW);
    digitalWrite(motor1_control_pin2, HIGH);
    digitalWrite(motor2_control_pin1, HIGH);
    digitalWrite(motor2_control_pin2, HIGH);
}

//Turn GoPiGo right slow (one motor off, better control)
void right()
{
    digitalWrite(motor1_control_pin1, HIGH);
    digitalWrite(motor1_control_pin2, HIGH);
    digitalWrite(motor2_control_pin1, LOW);
    digitalWrite(motor2_control_pin2, HIGH);
}

i’m not sure if i can add functionality to the firmware, but if i could, i’d like to add something like this:

//Turn GoPiGo Left slow (one motor off, better control)
void left_ccw()
{
    digitalWrite(motor1_control_pin1, HIGH);
    digitalWrite(motor1_control_pin2, LOW);
    digitalWrite(motor2_control_pin1, HIGH);
    digitalWrite(motor2_control_pin2, HIGH);
}

//Turn GoPiGo right slow (one motor off, better control)
void right_ccw()
{
    digitalWrite(motor1_control_pin1, HIGH);
    digitalWrite(motor1_control_pin2, HIGH);
    digitalWrite(motor2_control_pin1, HIGH);
    digitalWrite(motor2_control_pin2, LOW);
}

or, is there a way to control the rotation directly in python?

thanks,
t


#3

Hi,
Right now to turn left there are two options available:

  1. left(): Rotate the right wheel forward and stop the left wheel and the GoPiGo turns left.
  2. left_rot(): Rotate the right wheel forward and rotate the left wheel back and the GoPiGo rotates left.
    It’s similar for right too.

Isn’t rotating clockwise means to rotate right and rotating ccw means to rotate right? If it does, then you can use those function. Sorry if I got something wrong.

If it does not, then there are not other rotation functions and you are pretty correct in figuring out how to change it in the firmware.

I’ll just outline what all changes you’ll have to make to get it to work:

  1. First you’ll have to define a command number such as #define left_cmd 97. This is the command sent by the python program and which is interpreted by the firmware. Check here:https://github.com/DexterInd/GoPiGo/blob/b7c4254924df568039fb85ce0ec4f78ab05df470/Firmware/fw_ver_11/fw_ver_11.ino#L45 .

  2. Next you need a function to do what you want on that command: https://github.com/DexterInd/GoPiGo/blob/b7c4254924df568039fb85ce0ec4f78ab05df470/Firmware/fw_ver_11/fw_ver_11.ino#L128-L134 .

  3. Next you need a condition to call the function when that command is received https://github.com/DexterInd/GoPiGo/blob/b7c4254924df568039fb85ce0ec4f78ab05df470/Firmware/fw_ver_11/fw_ver_11.ino#L420-L421

  4. That’s it on the firmware. On the python library you’ll have to make changes to send the command too. First define the command: https://github.com/DexterInd/GoPiGo/blob/b7c4254924df568039fb85ce0ec4f78ab05df470/Software/Python/gopigo.py#L42

  5. Next add the send sequence: https://github.com/DexterInd/GoPiGo/blob/b7c4254924df568039fb85ce0ec4f78ab05df470/Software/Python/gopigo.py#L121-L122

  6. Now you can use the command.

It’s a bit long and cumbersome process but once you get the hang of it, it is much better.

Also, be careful when you upload the code. Make sure that the motor is disconnected because one of the SPI lines is connected to the Motor Controller chip and you might burn your GoPiGo if you are not careful.

-Karan


#4

hi karan,

thanks for your thorough reply. i got busy, and i’m now just getting back to this.

anyway, i’ll try using your instructions soon. what i’m looking to do is to be able to independently control the direction and speed of rotation of each wheel/motor. i wouldn’t be using the gpg at a mobile robot, but for a video installation project where i need to control the rotation of one or more surfaces that will be screens for video projections.

i’ll let you know how it goes.

thanks again,
tracy

p.s. i read on another topic that the tape on the rotation encoding wheels should not be removed? true? if so, i missed that detail and removed the tape. the gpg seems to work ok though.


#5

Hi Tracy,
We’ll let you know as soon as the firmware is ready. As for the encoders, they are used with PID algorithm to make sure that both the motors run at the same speed. If you face any problems with the motors not working properly, just use masking tape to cover the encoder.

-Karan


#6

Hi Karan,

Finally had time to try modifying the firmware as you suggested. I believe that I’ve made all of the needed edits to the files (gopigo.py and fw_ver_11.ino), but it doesn’t work.

I’ve created a Python test script to test the changes, and the new commands seem to be recognized (no errors or warnings when i run the test), but the gpg doesn’t respond. My test is an edited version of the basic_test_all.py script. All of the other original commands work (i.e., “left()”, “fwd()”), but my new commands seem to be ignored.

I think the problem may be that a new hex file fw_ver_11.cpp.hex is has not been generated with my changes? What do you think?

If so, how do I update fw_ver_11.cpp.hex with my changes? Sorry, I’m a Python newbie.

Thanks,
tracy


#7

Hey Tracy,
Are you sure that you have made the changes in both the python library and the firmware with the same set of command like https://github.com/DexterInd/GoPiGo/blob/b5edb37a4e7bf38d285fa6595c5676e099c5d731/Firmware/fw_ver_11/fw_ver_11.ino#L401-L406 and https://github.com/DexterInd/GoPiGo/blob/b5edb37a4e7bf38d285fa6595c5676e099c5d731/Software/Python/gopigo.py#L141-L142 for increase speed command.

If you think the problem is with the hex. The easiest way might be to enable the verbose mode in Arduino IDE and copy the location of the HEX file generated and try it again. This should help: https://alselectro.wordpress.com/2014/01/26/where-are-the-hex-files-compiled-by-arduino/ .

Let us know if this helps.

-Karan