Once the motors were connected to the motor controller (see previous post), I started working on writing the code for basic robot movement. The basic motor commands are:
- onFwd/onRev: move each motor independently in the forward or reverse direction
- off/stop: stop either motor gradually (float) or abruptly (break)
- fwdRight/fwdLeft: turn the robot by running the two motors at different speeds in the forward direction
- revRight/revLeft: turn the robot by running the two motors at different speeds in the reverse direction
- turnRight/turnLeft: turn the robot by running the two motors in the opposite directions
The names of these functions are inspired by the motor functions in NQC and NXC, which I use for the LEGO Mindstorms Robots.
Each of these functions manipulate the three control signals for each motor as shown in the this code snippet:
void Motor::onFwd(int motor, int speed) { int val = map(speed, 0, 100, 0, 255); switch (motor) { case Motor_R: // Right Motor analogWrite (enbPinA, val); digitalWrite (fwdPinA, HIGH); digitalWrite (bkdPinA, LOW); break; case Motor_L: // Left Motor ...
Finally, the Motor control library can be downloaded from here.
Andrew,
– make sure that the batteries are fully charged.
– make sure that jumpers VR1-VR4 and 5V_EN in the controller card are OPEN and jumpers CSA and CSB are CLOSED.
– upload the sketch below for direct control of the motors. The sketch will turn the motors for 5 sec intervals. if it is still slow, remove one of the motors on each side so only one motor is connected to the A and B sides in the controller
when i set speed >100 car dont runcompletly (in air)
when i set speed <100 and use motor.onFwd(0,90) only left motors work and run very slow…. I completly check all cables and all contected by your scheme
The motor should run at any speed without friction (left the car in the air). Make sure the batteries are charged and the wiring is correct.
Ok, thanks.. but my car dont run when i set <100 to speed parameter 🙁
Andrew,
The speed parameter in the motor commands takes a value from 0 to 100 and maps it to 0 to 255 (for PWM). So 100 means 100% power and 50 means 50% power and so on. Maybe I should have called the parameter power instead of speed to be accurate. I found that the robot needs to be on 100% power to turn properly on carpet. In general, I think the battery is not providing enough power for all four motors and the fraction caused by the imperfectly aligned wheels is too high.
One morequestion about Motor library, how can i change the speed ofcar. itryto use motor.onFwd(0,50), motor.onFwd(0,100), motor.onFwd(0,150), motor.onFwd(0,200) but car dont work fine and dont change the speed. Can you say something about that?
Please see this post “Arduino robot kit – Wiring Diagram”
Hi, can you give full scheme of this car, i cant understend some things with motors. And pls make some more tutorials for this, i cant completly make it work. Thank you