I recently assembled the Zumo Robot. I wanted a simple robot that I could learn from and do some simple coding. I would like a simple sketch to move the robot forward then turn left, pause then move forward and so on.
I took a look at the example in the Zumo Motors and some of the other examples. These are way beyond what I want right now. Can anyone provide me a simple sketch to move the robot forward, turn left, turn right, reverse and stop. I am having a hard time figuring out how to make the robot move to a specific length or duration then turn and move in a different direction for a specific duration or length.
I looked through the forum and I did not see any posts for this information.
The delay determines how long the motor runs for in milliseconds (so 2000 would be 2 seconds) between motor commands. The “speed” is a number form -400 and 400, with negative numbers causing the motor to turn in the reverse direction and “0” being stopped."
This is kind of what I had in mind. I put this together with some ideas I gathered here and there. I played around with this for awhile until I was able to get it to run around in a rectangle. Simple not complicated. I am running 1:150 motors so I am not moving as fast as the standard motors that come with the pre-assembled version. If you are running those you might want to slow it down some. I am working on a ping sensor to add to it and a servo.
/*
Simple sketch to move the Zumo robot forward and turn in a
rectangle then stop and repeat
by KWReader 2/2014
*/
#include <ZumoMotors.h>
#define LED_PIN 13
#define REVERSE_SPEED 200 // 0 is stopped, 400 is full speed
#define TURN_SPEED 200
#define FORWARD_SPEED 200
#define REVERSE_DURATION 500 // ms
#define TURN_DURATION 500 // ms
#define FORWARD_DURATION 5000 // ms
#define STOP 0 // 0 is stopped
#define STOP_DURATION 100 // ms
ZumoMotors motors;
void setup()
{
pinMode(LED_PIN, OUTPUT);
// uncomment one or both of the following lines if your motors' directions need to be flipped
//motors.flipLeftMotor(true);
//motors.flipRightMotor(true);
}
void loop()
{
motors.setSpeeds(FORWARD_SPEED,FORWARD_SPEED);
delay(FORWARD_DURATION);
motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
delay(TURN_DURATION);
motors.setSpeeds(FORWARD_SPEED,FORWARD_SPEED);
delay(FORWARD_DURATION);
motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
delay(TURN_DURATION);
motors.setSpeeds(STOP, STOP);
delay(STOP_DURATION);
motors.setSpeeds(REVERSE_SPEED,REVERSE_SPEED);
delay(REVERSE_DURATION);
}