An original Arduino library to interface w/ the Robotics Club @ UNT's own RoverBot.
- Download the RoverUNT Arduino Library here.
- Follow these instructions to import the library into the Arduino IDE.
After installing the RoverUNT Library, include the library in the top of your Arduino Sketch.
#include <RoverUNT.h>
After it's imported, create an instance of the Rover class.
Rover* Bot
const int MAX = 255; // max speed
void setup() {
int leftSpeedPin = 9; // enb
int leftForwardPin = 8; // in3
int leftBackwardPin = 7; // in4
int rightSpeedPin = 3; // ena
int rightForwardPin = 5; // in2
int rightBackwardPin = 4; // in1
Bot = new Rover(
leftSpeedPin,
leftForwardPin,
leftBackwardPin,
rightSpeedPin,
rightForwardPin,
rightBackwardPin
);
Serial.begin(9600);
Serial.println("<Arduino is ready>");
delay(2000);
}
A good way to test if your sketch is setup correctly with your hardware is to make the Rover move forward. This will confirm if both wheels rotate in the same direction - otherwise, modify your pin assignments in your code.
// ...
void loop() {
Bot->forward(MAX); // MAX == 255
}
// ...
-
Move the Rover forward at a defined
speed. -
speedis a PWM value between 0 and 255. -
Usage
Bot->forward(255);
-
Move the Rover backward at a defined
speed. -
speedis a PWM value between 0 and 255. -
Usage
Bot->backward(255);
-
Stop the Rover from moving.
-
Usage
Bot->stop();
-
Rotate the Rover counter-clockwise at a defined speed
-
speedis a PWM value between 0 and 255. -
Usage
Bot->rotateLeft(255);
-
Rotate the Rover clockwise at a defined speed
-
speedis a PWM value between 0 and 255. -
Usage
Bot->rotateRight(255);
-
Move the Rover's left motor forward at a defined
speed. -
speedis a PWM value between 0 and 255. -
Usage
Bot->leftMotorForward(255);
-
Move the Rover's left motor backward at a defined
speed. -
speedis a PWM value between 0 and 255. -
Usage
Bot->leftMotorBackward(255);
-
Stop the Rover's left motor from moving.
-
Usage
Bot->leftMotorStop();
-
Move the Rover's right motor forward at a defined
speed. -
speedis a PWM value between 0 and 255. -
Usage
Bot->rightMotorForward(255);
-
Move the Rover's right motor backward at a defined
speed. -
speedis a PWM value between 0 and 255. -
Usage
Bot->rightMotorBackward(255);
-
Stop the Rover's right motor from moving.
-
Usage
Bot->rightMotorStop();
- Add a short delay with a stop to prevent the motors from sparking on sudden spin changes:
void loop() {
Bot->rotateLeft();
delay(1000); // rotate left for one second
Bot->stop(); // stop
delay(200) // and short delay to prevent sparking
Bot->rotateRight();
delay(1000); // rotate right for one second
Bot->stop(); // stop
delay(200) // and short delay to prevent sparking
}