robotshop.com/en/robotshop-r … RB-Rbo-118
I’ve uploaded the code provided in the rover development manual found on your website, but when I run the code in the arduino software, errors are found.
Do you have an updated code (sketch) for this project?
Where can I get an updated code to control your project?
Thanks for any help you can provide.
MC
Can you try this code? I changed the Serial.print(…, BYTE) for Serial.write(…);
/*
Arduino Code
The following demo code is complied in Arduino (www.arduino.cc) and uses two
subroutines. You are free to copy/paste the code into the Arduino compiler.
Ensure the motor controller is connected properly before use.
The serial data line of the motor controller should be connected to pin 1 (Tx) on the Arduino.
*/
int servopulse1 = 1250; //test servo tilt position (0deg =0 to 180deg =1500)
int servopulse2 = 1500; //test servo pan position (0deg =0 to 180deg =1500)
int servopin1 = 9; //yellow wire from servo 1 to digital pin 9
int servopin2 = 10; //yellow wire fromservo 2 to digital pin 10
int motor_reset = 2; //motor reset pin connected to digital pin 2
void setup()
{
pinMode(motor_reset, OUTPUT); //sets pin as output
pinMode(servopin1, OUTPUT); //sets pin as output
pinMode(servopin2, OUTPUT); //sets pin as output
//digitalWrite(motor_reset, LOW); //do not activate motor driver
Serial.begin(9600); //communication at 9600 baud
// reset motor controller
digitalWrite(motor_reset, LOW);
delay(50);
digitalWrite(motor_reset, HIGH);
delay(50); // reset delay
}
void loop()
{
servoposition(); // subroutine servoposition
motorcontrol(); // subroutine motor control
}
//subroutine servoposition
void servoposition()
{
digitalWrite(servopin1, HIGH); // Start the pulse to servo 1
delayMicroseconds(servopulse1); // Length of the pulse sets the servo position
digitalWrite(servopin1, LOW); // Stop the pulse
digitalWrite(servopin2, HIGH); // Start the pulse to servo 2
delayMicroseconds(servopulse2); // Length of the pulse sets the motor position
digitalWrite(servopin2, LOW); // Stop the pulse
}
//subroutine motor control
void motorcontrol()
{
//left motor
unsigned char buff1[6];
buff1[0]=0x80; //start byte specific to Pololu motor controller
buff1[1]=0x00; //Device type byte specific to Pololu controller
buff1[2]=0x01; //Motor number and direction byte; motor one =00,01
buff1[3]=0x7F; //Motor speed "0 to 128" (ex 100 is 64 in hex)
for(int i=0;i<4;i++) {
Serial.write(buff1 i]);
}
//right motor
unsigned char buff2[6];
buff2[0]=0x80; //start byte - do not change
buff2[1]=0x00; //Device type byte
buff2[2]=0x03; //Motor number and direction byte; motor two=02,03
buff2[3]=0x7F; //Motor speed "0 to 128" (ex 100 is 64 in hex)
for(int i=0;i<4;i++) {
Serial.write(buff2 i]);
}
}
Firstly, Thank you for your help. The code has no errors when applied to the arduino coding app.
I noticed a servo subroutine in the code; is this routine for the control of the “pan and tilt” kit?
Second, My rover is powered with the two GM9-90 deg motors and I would like to control the rover with the
“RB-Dfr-92” remote kit.
Will your supplied code work with the remote or will I need to add another subroutine for the IR kit?
Thank You
CHENIER
That’s right, the servo code is a starting point for using the pan and tilt system. You will need to make modifications, depending on your needs.
The sample code is made to control a RB-Pol-16 motor controller that can be used to control your GM9 motors.
The code doesn’t have any support for the IR kit, so you will need to modify the code, but there is an Arduino library for the IR kit in the Useful Links section that can be added to the sample code.