Reverse motor in code #36
-
|
How do you reverse a motor in code? Is there a list of gizmo commands available somewhere we've over looked? Thanks! -david |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Reversing a motor isn't gizmo specific, so there wasn't anything in our docs for you to overlook. Based on your other thread I'll assume this is in the context of Arduino. In the Arduino environment using VeX MC-29 motor controllers motors are modeled as servos in continuous rotation mode. The main arduino docs for the servo libarary can be found here, but the gist of the solution is that the servo If you just want to reverse which direction is considered to be "forward" I would suggest you might want to do that electrically by just flipping the polarity on the motor in question. |
Beta Was this translation helpful? Give feedback.
-
|
I believe the Arduino sample code from BEST has a bug in it where they send the same command to the left and right motor causing your robot to go around in circles. The solution is to either reverse the wires on the motor (a really bad idea, don't do it), or remap the right motor. While I don't understand the concept of the 0 to 180 with 90 in the middle (all other robot code I've programmed in use -127 to 127 with 0 meaning stop and I received furled brows from my students as well trying to teach them this.:), to reverse it (ala the "reverse" command or "false"), you need to remap the values using the map() function. speed = map(speed, 0, 180, 180, 0); |
Beta Was this translation helpful? Give feedback.
Reversing a motor isn't gizmo specific, so there wasn't anything in our docs for you to overlook. Based on your other thread I'll assume this is in the context of Arduino. In the Arduino environment using VeX MC-29 motor controllers motors are modeled as servos in continuous rotation mode. The main arduino docs for the servo libarary can be found here, but the gist of the solution is that the servo
writefunction takes a value between 0 and 180, where 90 is stopped, 0 is full speed in one direction, and 180 is full speed in the other.If you just want to reverse which direction is considered to be "forward" I would suggest you might want to do that electrically by just flipping the polari…