Coding DFRobotShop Rover

Hi,

We understand that the DFRobotShop Rover is ideal not only for remote control but for autonomous programming. However, given the near infinite variety of possible third party sensor combinations which can be connected to the Rover, any code we create would need to be customized. We are entertaining the idea of creating an upgrade kit for the DFRobotShop Rover, but at this time it is just a concept.

The best appraoch is to to learn the software either by following the tutorials online or purchasing the Arduino book. The sample code in the manual uses “cases” which turn the motors at full speed in specific directions or have them stop. Cases however are not required and users are fee to create their own code, which is part of the learning process.

In order to make the Rover autonomous, you can send commands which have the rover move in specific directions for predetermined time (move forward for 5 seconds, then turn left for 2s, then move forward etc.). For true autonomous control, you would need to add a sensor (such as the Sharp distance sensor). Instead of using cases, you could use an “if” statement (if sensorvalue < 100, stop, reverse for 5 seconds, turn left, then continue).

We do appreciate the feedback that you would like autonomous code ready to go and we will likely do so with the creation of the upgrade kit.

Hope this helps,

Hi,

If you are new to coding, the best approach is not to modify a page worth of code, but rather to learn from the ground up. The Arduino microcontrollers are incredibly versatile, and the DFRobotShop Rover is intended to be a learning tool which has more features than a regular Arduino USB microcontroller. Once again, we suggest starting from scratch, going through the Arduino 5 minute tutorials, reading the tutorials on the Arduino website and proceeding step by step. When getting started in robotics, patience is critical (you can’t do everything immediately).

Currently there is no “default” autonomous code available for the DFRobotShop Rover as we are relying on the user community to devlop it based on their applications. We encourage those who have made code for the Rover to post it here, along with any additional parts / sensors they may be using.

Note that the basic Arduino board (RB-Ard-18) on which the DFRobotShop Rover is based, only has the Arduino website where users can learn how to program. The DFRobotShop Rover is essentially an Arduino main board, but adds a dual motor controller, voltage regulator and the necessary mechanics to make a mobile tracked platform. We supply the basic code to test that the platform is working, though users were still expected to go through the learning process.

Sincerely,

Hi Markl,

It was certainly nice of you to post the code you created and we hope others find it helpful. In regard to the issue you are having, can you provide a photo? If there is a short circuit, don’t try to plug it in until you are confident the issue is resolved.

Sincerely,

No it does not help, even the simplest of bump and go mechanical feelers code would be of help. That at least would give me some use out of this thing. All the samples do not lead to modification for this kind of use. All I get is syntax errors when I try to modify any thing out there. Is this too much to ask, how about some of the forum members? Take pity on this novice otherwise all I have is an expressive paper weight
UncleMike

[code]

[/code]To: UncleMike

I feel your pain, when I started I robotics I wanted code too. I followed some instructions and tutorials from the arduino website and started simple. First I learned how to blink an led connected to digital pin 13 and ground. Then I moved up to fading the led. You should defiantly try learning how to code. But I did write up some code to test out the sensors that are built into the robot. The following code reads out the ldr, the raw adc value from the temperature senor and then the temperature in Celsius.

/*  A simple temperature sensor check program */
#include <math.h> 

const int analogpin = 0;  // Analog input pin
double Temp;

void setup()
{
  Serial.begin(9600);   // initialize serial communications at 9600 bps:
}

void loop()
{
  int adcvalue = analogRead(analogpin);    // read the analog in value:            

  double Temp2 = adcvalue;
  double Temp1 = adcvalue / 25.6;  //convert it to Celsius
  Temp = (Temp1 * 9.0)/ 5.0 + 32.0; //convert to Fahrenheit 
 
   

  Serial.print("\nTemp in Celsius: ");
  Serial.print(Temp1);
  delay(1000);
  Serial.print("\nTemp in Fahrenheit: ");
  Serial.print(Temp);
  delay(1000);   // wait 1 second before next sample                    
}

I was wondering if anyone could help me just to drive the tank to the left. The following is the code that I tried, but is unsuccessful.

int leftspeed, rightspeed = 255; //maxium speed 255
int SpeedControl1 = 6; //Speed controller
int SpeedControl2 = 5; //Speed controller
int Motor1 = 8; //Motor 1 connected to digital pin 8
int Motor2 = 7; //Motor 2 connected to digital pin 7
char a,b;

void setup(){
Serial.begin(9600);

}

void loop(){
digitalWrite (SpeedControl1,a); //Move the tank left
digitalWrite(Motor1,HIGH);
digitalWrite (SpeedControl2,b);
digitalWrite(Motor2,LOW);

}

Also I wrote some code to just control the direction of the tank with a delay of 5 seconds in between.

int E1 = 6; //M1 Speed Control 
int E2 = 5; //M2 Speed Control 
int M1 = 8; //M1 Direction Control 
int M2 = 7; //M2 Direction Control 

void setup(){

 
}
void loop(){
  analogWrite (E1,255); //Foward
  digitalWrite(M1,LOW); 
  analogWrite (E2,255); 
  digitalWrite(M2,LOW); 
  delay(5000);
  analogWrite (E1,255); //Reverse
  digitalWrite(M1,HIGH); 
  analogWrite (E2,255); 
  digitalWrite(M2,HIGH); 
  delay(5000);
  analogWrite (E1,255); //Left
  digitalWrite(M1,HIGH); 
  analogWrite (E2,255); 
  digitalWrite(M2,LOW); 
  delay(5000);
  analogWrite (E1,255); //Right
  digitalWrite(M1,LOW); 
  analogWrite (E2,255); 
  digitalWrite(M2,HIGH);
  delay(5000);
}

I have to charge my camera, so I can’t get the photo just yet. But, I did write some more code. I attached two light dependent resistors to analog pins 6 and 7 so it does not interfere with the built in sensors. The code is far from perfect but I though it might come useful to someone. Also you if you dont have any ldrs, then you can just use the built in one on the tank.

[code]//Speed, speed controller, and motor declartion

int E1 = 6; //Speed controller
int E2 = 5; //Speed controller
int M1 = 8; //Motor 1 connected to digital pin 8
int M2 = 7; //Motor 2 connected to digital pin 7

//Sensors
const int leftLight = 6; //1 Light dependent resistor connected to analog pin 6
const int rightLight = 7; //2 Light dependent resistor connected to analog pin 7

void setup(){
Serial.begin(9600);//For testing/debugging
pinMode(13,OUTPUT);
}

void loop(){
int leftReading = analogRead(leftLight);
int rightReading = analogRead(rightLight);

Serial.print("\nleftReading:");
Serial.print(leftReading);
delay(1000);
Serial.print("\nrightReading:");
Serial.print(rightReading);
delay(1000);

if (leftReading > rightReading){
analogWrite (E1,255); //Right
digitalWrite(M1,LOW);
analogWrite (E2,255);
digitalWrite(M2,HIGH);
delay(1000);
}

if (rightReading > leftReading){
analogWrite (E1,255); //Left
digitalWrite(M1,HIGH);
analogWrite (E2,255);
digitalWrite(M2,LOW);
delay(1000);
}

if (leftReading < 5 || rightReading < 5){
analogWrite (E1,255);
digitalWrite(M1,HIGH);
analogWrite (E2,255);
digitalWrite(M2,HIGH);

}

if( leftReading > 30 || rightReading > 30){
digitalWrite(13, HIGH);
}

else
{
digitalWrite(13, LOW);
}

}[/code]