Forum >Devastator Robot Won't Rotate
RoboticsGeneral

Devastator Robot Won't Rotate

userHead paul.hallam.woodville 2017-01-01 06:22:08 8343 Views19 Replies
I have the Devastator Robot Kit (SKU:ROB0125) and was trying the obstacle avoidance sample code as described in the tutorials chapter 4. The robot moved forwards OK, but when it detected an obstacle it would only reverse, it never tried to turn as the obstacle avoiding function should make it do.
I created a sample program to see what was happening and it appears that:
- If I set both motors to a clockwise direction, the robot moves forwards as expected
- If I set both motors to an anticlockwise direction, the robot moves backwards as expected
- If I set one motor to clockwise and the other to anticlockwise, the robot doesn't rotate as expected, but moves backwards

What am I doing wrong?
Sample code that demonstrates the behaviour below:
[code]
#include <DFRobot.h>
#include <IIC1.h>
DFrobotEdison L_Motor;
DFrobotEdison R_Motor;

void setup() {
// Initialize the motor drives
L_Motor.begin(M2);
R_Motor.begin(M1);
}

void loop() {
// Set motor speed
L_Motor.setSpeed(55);
R_Motor.setSpeed(55);

// Robot moves forward
L_Motor.setDirection(CLOCKWISE);
R_Motor.setDirection(CLOCKWISE);
delay(2000);

// Robot moves backward
L_Motor.setDirection(ANTICLOCKWISE);
R_Motor.setDirection(ANTICLOCKWISE);
delay(2000);

// Robot should rotate, but moves backward
L_Motor.setDirection(CLOCKWISE);
R_Motor.setDirection(ANTICLOCKWISE);
delay(2000);

// Robot should rotate, but moves backward
L_Motor.setDirection(ANTICLOCKWISE);
R_Motor.setDirection(CLOCKWISE);
delay(2000);

// Stop motors
L_Motor.stop();
R_Motor.stop();
delay(5000);
}
[/code]
2017-01-24 01:19:35 That's all right
The Code what I mentioned is the underlying code. You know Edison and Atmega8 uses IIC communication method. We can bypass Edison, control the motors with ATmega8 directly. That's very interesting!

According to the schematic, ATmega8 uses D7, D8, D9, D10 control the module
Acoording to the NG sample code, we can know the control logic. (it is just like a puzzle game)
M1: Direction: D8 PWM: D10
M2: Direction: D7 PWM: D9

As you have known these information, you can control the motor without Edison. (you ‘ll know whether it's a hardware issue.)

[Code/]

int E1 = 10;
int M1 = 8;
int E2 = 9;
int M2 = 7;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop()
{
advance();
delay(3000);
turn_R();
delay(3000);
turn_L();
delay(3000);
back_off();
delay(3000);

}

void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void advance() //Move forward
{
analogWrite (E1,200); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,200);
digitalWrite(M2,HIGH);
}
void back_off() //Move backward
{
analogWrite (E1,200);
digitalWrite(M1,LOW);
analogWrite (E2,200);
digitalWrite(M2,LOW);
}
void turn_L() //Turn Left
{
analogWrite (E1,200);
digitalWrite(M1,LOW);
analogWrite (E2,200);
digitalWrite(M2,HIGH);
}
void turn_R() //Turn Right
{
analogWrite (E1,200);
digitalWrite(M1,HIGH);
analogWrite (E2,200);
digitalWrite(M2,LOW);
}


[/Code]
userHeadPic Grey.CC
2017-01-24 01:19:35 That's all right
The Code what I mentioned is the underlying code. You know Edison and Atmega8 uses IIC communication method. We can bypass Edison, control the motors with ATmega8 directly. That's very interesting!

According to the schematic, ATmega8 uses D7, D8, D9, D10 control the module
Acoording to the NG sample code, we can know the control logic. (it is just like a puzzle game)
M1: Direction: D8 PWM: D10
M2: Direction: D7 PWM: D9

As you have known these information, you can control the motor without Edison. (you ‘ll know whether it's a hardware issue.)

[Code/]

int E1 = 10;
int M1 = 8;
int E2 = 9;
int M2 = 7;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop()
{
advance();
delay(3000);
turn_R();
delay(3000);
turn_L();
delay(3000);
back_off();
delay(3000);

}

void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void advance() //Move forward
{
analogWrite (E1,200); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,200);
digitalWrite(M2,HIGH);
}
void back_off() //Move backward
{
analogWrite (E1,200);
digitalWrite(M1,LOW);
analogWrite (E2,200);
digitalWrite(M2,LOW);
}
void turn_L() //Turn Left
{
analogWrite (E1,200);
digitalWrite(M1,LOW);
analogWrite (E2,200);
digitalWrite(M2,HIGH);
}
void turn_R() //Turn Right
{
analogWrite (E1,200);
digitalWrite(M1,HIGH);
analogWrite (E2,200);
digitalWrite(M2,LOW);
}


[/Code]
userHeadPic Grey.CC
2017-01-23 05:53:09 Hi Grey,

Thanks for getting involved in this and trying to help - it's much appreciated!
I also wondered if I had the old ATmega8 firmware, so I bought an FTDI programmer and updated it to see if that fixed it.
Sadly, it didn't fix it.
I even temporarily amended the firmware so that the forward and backward direction commands were reversed, just to prove I was actually updating the firmware.
What test code do you want to see?
There is already three pieces of code referenced in the thread:
I started with the Autocar V1.2 sample code, where I noticed it only reversed instead of rotating.
So I then created the test code that I included in the first post in this thread.
There is also the sample code in the last post by Wendy that I tried.
In all three cases the robot reverses whenever the motor directions are set in opposite directions instead of rotating as it should.
Set both motors to forwards and the robot moves forwards.
Set both motors to backwards and the robot moves backwards.
Set one motor to forwards and one to backwards (in either combination) and it moves backwards - very odd behaviour.

Thanks... Paul
userHeadPic paul.hallam.woodville
2017-01-23 05:53:09 Hi Grey,

Thanks for getting involved in this and trying to help - it's much appreciated!
I also wondered if I had the old ATmega8 firmware, so I bought an FTDI programmer and updated it to see if that fixed it.
Sadly, it didn't fix it.
I even temporarily amended the firmware so that the forward and backward direction commands were reversed, just to prove I was actually updating the firmware.
What test code do you want to see?
There is already three pieces of code referenced in the thread:
I started with the Autocar V1.2 sample code, where I noticed it only reversed instead of rotating.
So I then created the test code that I included in the first post in this thread.
There is also the sample code in the last post by Wendy that I tried.
In all three cases the robot reverses whenever the motor directions are set in opposite directions instead of rotating as it should.
Set both motors to forwards and the robot moves forwards.
Set both motors to backwards and the robot moves backwards.
Set one motor to forwards and one to backwards (in either combination) and it moves backwards - very odd behaviour.

Thanks... Paul
userHeadPic paul.hallam.woodville
2017-01-23 01:51:53 Hi Paul,

Do you have a FTDI programmer? Romeo Edison uses ATmega8 to drive Analog ports and motor driver chip. I'm guessing what you have is a old version. Here is a wiki tutorial, please check:make_clickable_callback(MAGIC_URL_FULL, ' ', 'https://goo.gl/YzmbDk', '', ' class="postlink"')
BTW, could you share your test code now?
userHeadPic Grey.CC
2017-01-23 01:51:53 Hi Paul,

Do you have a FTDI programmer? Romeo Edison uses ATmega8 to drive Analog ports and motor driver chip. I'm guessing what you have is a old version. Here is a wiki tutorial, please check:make_clickable_callback(MAGIC_URL_FULL, ' ', 'https://goo.gl/YzmbDk', '', ' class="postlink"')
BTW, could you share your test code now?
userHeadPic Grey.CC
2017-01-22 02:54:43 Hi Wendy,

I tried that sample code you attached and that behaves the same way as all the other things I have tried - the robot just runs backwards, with no rotation at all.
userHeadPic paul.hallam.woodville
2017-01-22 02:54:43 Hi Wendy,

I tried that sample code you attached and that behaves the same way as all the other things I have tried - the robot just runs backwards, with no rotation at all.
userHeadPic paul.hallam.woodville
2017-01-21 01:41:57 Hi Paul,

Sorry, its strange. I have no idea about that. I have give a feedback to our team, any update I will let you know. And there is a sample code in the attachment, maybe you can try again.
[attachment=0]sketch_jan20a.rar[/attachment]
userHeadPic Wendy.Hu
2017-01-21 01:41:57 Hi Paul,

Sorry, its strange. I have no idea about that. I have give a feedback to our team, any update I will let you know. And there is a sample code in the attachment, maybe you can try again.
[attachment=0]sketch_jan20a.rar[/attachment]
userHeadPic Wendy.Hu
2017-01-17 09:32:58 Hi Wendy,

Sorry to take so long getting back to you, I haven't been able to to do anything with the robot for a while!

Yes I used your sample code - where I previously mentioned the code in the tutorial chapter 4, I was referring to your Autocar V1.2 sample code. Running it unaltered, the robot just reverses instead of turning when it detects an obstacle.
I tried increasing the time the robot should spend turning and it still just reverses, rather than turn - it just reverses further back.
I'm pretty sure that connections are correct, especially as the robot moves forward or backwards as expected - it's just when the code sets the two motor directions to opposite directions (one clockwise and one anti-clockwise) that it doesn't behave as expected.
I appreciate your efforts to try and resolve this - any more suggestions? :)

Thanks... Paul
userHeadPic paul.hallam.woodville
2017-01-17 09:32:58 Hi Wendy,

Sorry to take so long getting back to you, I haven't been able to to do anything with the robot for a while!

Yes I used your sample code - where I previously mentioned the code in the tutorial chapter 4, I was referring to your Autocar V1.2 sample code. Running it unaltered, the robot just reverses instead of turning when it detects an obstacle.
I tried increasing the time the robot should spend turning and it still just reverses, rather than turn - it just reverses further back.
I'm pretty sure that connections are correct, especially as the robot moves forward or backwards as expected - it's just when the code sets the two motor directions to opposite directions (one clockwise and one anti-clockwise) that it doesn't behave as expected.
I appreciate your efforts to try and resolve this - any more suggestions? :)

Thanks... Paul
userHeadPic paul.hallam.woodville
2017-01-06 19:40:27 Hi

The robot looks like no problem, or it will not be able to back and forward. Looks more like there are something wrong with the code. Lets find the problem together.
Did you download the sample code from our website page? If so, did you try to upload the the sample code named Autocar to see what happened? The sample code you can refer to the attachment. Then I would like to suggest you can modify the delay time longer to see if the robot can turn right or left properly. And just a reminder, please make sure your diagram is correct and same with the pin definition in the code.

Looking forward to your reply. :)
userHeadPic Wendy.Hu
2017-01-06 19:40:27 Hi

The robot looks like no problem, or it will not be able to back and forward. Looks more like there are something wrong with the code. Lets find the problem together.
Did you download the sample code from our website page? If so, did you try to upload the the sample code named Autocar to see what happened? The sample code you can refer to the attachment. Then I would like to suggest you can modify the delay time longer to see if the robot can turn right or left properly. And just a reminder, please make sure your diagram is correct and same with the pin definition in the code.

Looking forward to your reply. :)
userHeadPic Wendy.Hu
2017-01-05 10:24:19 Hi,
Yes, I started with the code in the tutorial chapter 4. With that code the robot would only reverse when it detected an obstacle, it wouldn't turn. I wrote the sample code above to confirm that there wasn't a logic error in the obstacle avoidance function.
Looking at the Atmega8 firmware and the board schematic, it's hard to see why this doesn't do what it should. Do you think I have a faulty driver board?
Thanks... Paul
userHeadPic paul.hallam.woodville
2017-01-05 10:24:19 Hi,
Yes, I started with the code in the tutorial chapter 4. With that code the robot would only reverse when it detected an obstacle, it wouldn't turn. I wrote the sample code above to confirm that there wasn't a logic error in the obstacle avoidance function.
Looking at the Atmega8 firmware and the board schematic, it's hard to see why this doesn't do what it should. Do you think I have a faulty driver board?
Thanks... Paul
userHeadPic paul.hallam.woodville
2017-01-04 02:36:17 Hi

According to the code you provided, it should be no problem. :( I have no idea about that. Did you refer to our tutorial to do some test? And what happened?

Looking forward to your reply.
userHeadPic Wendy.Hu
2017-01-04 02:36:17 Hi

According to the code you provided, it should be no problem. :( I have no idea about that. Did you refer to our tutorial to do some test? And what happened?

Looking forward to your reply.
userHeadPic Wendy.Hu
2017-01-01 06:22:08 I have the Devastator Robot Kit (SKU:ROB0125) and was trying the obstacle avoidance sample code as described in the tutorials chapter 4. The robot moved forwards OK, but when it detected an obstacle it would only reverse, it never tried to turn as the obstacle avoiding function should make it do.
I created a sample program to see what was happening and it appears that:
- If I set both motors to a clockwise direction, the robot moves forwards as expected
- If I set both motors to an anticlockwise direction, the robot moves backwards as expected
- If I set one motor to clockwise and the other to anticlockwise, the robot doesn't rotate as expected, but moves backwards

What am I doing wrong?
Sample code that demonstrates the behaviour below:
[code]
#include <DFRobot.h>
#include <IIC1.h>
DFrobotEdison L_Motor;
DFrobotEdison R_Motor;

void setup() {
// Initialize the motor drives
L_Motor.begin(M2);
R_Motor.begin(M1);
}

void loop() {
// Set motor speed
L_Motor.setSpeed(55);
R_Motor.setSpeed(55);

// Robot moves forward
L_Motor.setDirection(CLOCKWISE);
R_Motor.setDirection(CLOCKWISE);
delay(2000);

// Robot moves backward
L_Motor.setDirection(ANTICLOCKWISE);
R_Motor.setDirection(ANTICLOCKWISE);
delay(2000);

// Robot should rotate, but moves backward
L_Motor.setDirection(CLOCKWISE);
R_Motor.setDirection(ANTICLOCKWISE);
delay(2000);

// Robot should rotate, but moves backward
L_Motor.setDirection(ANTICLOCKWISE);
R_Motor.setDirection(CLOCKWISE);
delay(2000);

// Stop motors
L_Motor.stop();
R_Motor.stop();
delay(5000);
}
[/code]
userHeadPic paul.hallam.woodville