Forum >Romeo BLE (SKU:DFR0305) GoBLE controlled 2wd robot
Romeo BLE (SKU:DFR0305) GoBLE controlled 2wd robot

I am having an issue with the motor control, when I try to move forwards or backwards one of the wheels is spinning at half the speed of the other. The wheel that is spinning slower interchanges when you switch from going backwards to forwards. When turning left or right this issue is not apparent. Any help would be appreciated, thanks.
[code]
#include <Servo.h>
#include <Metro.h>
#include "GoBLE.h"
#include <DFRobot_utility.h>
DFRobotCar mycar (4, 5, 7, 6); //Motor pins
Servo MyServo;
//M1 is left wheel
//M2 is right wheel
int LeftWheelSpeed;
int RightWheelSpeed;
int SpeedX, SpeedY;
int joystickX, joystickY;
int buttonState[5];
void setup() {
Goble.begin();
Serial.begin(115200);
MyServo.attach(9);
MyServo.write(90);
mycar.changeDir (true, true);
}
void loop() {
if (Goble.available()) {
joystickY = Goble.readJoystickX();
joystickX = Goble.readJoystickY();
buttonState[SWITCH_UP] = Goble.readSwitchUp();
buttonState[SWITCH_DOWN] = Goble.readSwitchDown();
buttonState[SWITCH_LEFT] = Goble.readSwitchLeft();
buttonState[SWITCH_RIGHT] = Goble.readSwitchRight();
int SpeedX=2*joystickX-256; //Enable map value of gamepad stick from (1~255) to (-255~255)
int SpeedY=2*joystickY-256;
// Serial.println("speedX: "); //Debugging
// Serial.println(SpeedX);
// Serial.println("speedY: ");
// Serial.println(SpeedY);
if (SpeedX>100 || SpeedX<-100){ //when joystick X is pushed either way
LeftWheelSpeed=SpeedX;
RightWheelSpeed=SpeedX;
mycar.control (LeftWheelSpeed/2,RightWheelSpeed/2); //Original speed was too fast so it was halved
}
else if (SpeedY>100 || SpeedY<-100){
LeftWheelSpeed=SpeedY-80; //when joystick Y is pushed either way
RightWheelSpeed=-SpeedY-80;
mycar.control (LeftWheelSpeed/2,RightWheelSpeed/2);
}
else if (SpeedX==0 && SpeedY==0){
mycar.control (0,0);
if (buttonState[SWITCH_LEFT] == PRESSED && //Servo control
buttonState[SWITCH_RIGHT] == RELEASED) {
Serial.println("servo left");
MyServo.write(0);
}
}
else if (buttonState[SWITCH_RIGHT] == PRESSED &&
buttonState[SWITCH_LEFT] == RELEASED) {
Serial.println("servo right");
MyServo.write(180);
}
}
}
[/code]
[Edit]
I have rewritten the code and used this instead of the earlier motor control system
[Code]
if (SpeedX>50 || SpeedX<-50 || SpeedY>50 || SpeedY<50){
mycar.control ((SpeedY+SpeedX)/2,(SpeedY-SpeedX)/2);
}
else if (SpeedX<50 && SpeedX>-50 && SpeedY<50 && SpeedY>-50){
mycar.control (0,0);
[/Code]
The issue is still occurring though and it is very evident at low speeds when one will stop before the other. If anyone knows how to fix this issue, it would be greatly appreciated.
[code]
#include <Servo.h>
#include <Metro.h>
#include "GoBLE.h"
#include <DFRobot_utility.h>
DFRobotCar mycar (4, 5, 7, 6); //Motor pins
Servo MyServo;
//M1 is left wheel
//M2 is right wheel
int LeftWheelSpeed;
int RightWheelSpeed;
int SpeedX, SpeedY;
int joystickX, joystickY;
int buttonState[5];
void setup() {
Goble.begin();
Serial.begin(115200);
MyServo.attach(9);
MyServo.write(90);
mycar.changeDir (true, true);
}
void loop() {
if (Goble.available()) {
joystickY = Goble.readJoystickX();
joystickX = Goble.readJoystickY();
buttonState[SWITCH_UP] = Goble.readSwitchUp();
buttonState[SWITCH_DOWN] = Goble.readSwitchDown();
buttonState[SWITCH_LEFT] = Goble.readSwitchLeft();
buttonState[SWITCH_RIGHT] = Goble.readSwitchRight();
int SpeedX=2*joystickX-256; //Enable map value of gamepad stick from (1~255) to (-255~255)
int SpeedY=2*joystickY-256;
// Serial.println("speedX: "); //Debugging
// Serial.println(SpeedX);
// Serial.println("speedY: ");
// Serial.println(SpeedY);
if (SpeedX>100 || SpeedX<-100){ //when joystick X is pushed either way
LeftWheelSpeed=SpeedX;
RightWheelSpeed=SpeedX;
mycar.control (LeftWheelSpeed/2,RightWheelSpeed/2); //Original speed was too fast so it was halved
}
else if (SpeedY>100 || SpeedY<-100){
LeftWheelSpeed=SpeedY-80; //when joystick Y is pushed either way
RightWheelSpeed=-SpeedY-80;
mycar.control (LeftWheelSpeed/2,RightWheelSpeed/2);
}
else if (SpeedX==0 && SpeedY==0){
mycar.control (0,0);
if (buttonState[SWITCH_LEFT] == PRESSED && //Servo control
buttonState[SWITCH_RIGHT] == RELEASED) {
Serial.println("servo left");
MyServo.write(0);
}
}
else if (buttonState[SWITCH_RIGHT] == PRESSED &&
buttonState[SWITCH_LEFT] == RELEASED) {
Serial.println("servo right");
MyServo.write(180);
}
}
}
[/code]
[Edit]
I have rewritten the code and used this instead of the earlier motor control system
[Code]
if (SpeedX>50 || SpeedX<-50 || SpeedY>50 || SpeedY<50){
mycar.control ((SpeedY+SpeedX)/2,(SpeedY-SpeedX)/2);
}
else if (SpeedX<50 && SpeedX>-50 && SpeedY<50 && SpeedY>-50){
mycar.control (0,0);
[/Code]
The issue is still occurring though and it is very evident at low speeds when one will stop before the other. If anyone knows how to fix this issue, it would be greatly appreciated.
2017-01-26 02:11:08 Maybe the motor is also damaged. Do you have a multimeter? you can measure the output voltage of the motor driver.
If you don't, you can exchange two motors, and see whether it will happen on the other port.
Grey.CC
If you don't, you can exchange two motors, and see whether it will happen on the other port.

2017-01-25 22:24:15 If this is a hardware, you can mail to techsupport team:make_clickable_callback(MAGIC_URL_EMAIL, ' ', '[email protected]', '', '') for the replacement or anything else.
Grey.CC

2017-01-25 08:29:31 I Tried the code you sent. The issue still occurs at low speeds. Maybe its the hardware and not the software? Thanks anyway.
o.gooberman

2017-01-24 21:36:09 Uhm~ which code you are using now?
Try this code :
int E1 = 5;
int M1 = 4;
int E2 = 6;
int M2 = 7;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop()
{
digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 200); //PWM Speed Control
analogWrite(E2, 200); //PWM Speed Control
}
}
Note: Like what I said in this post:make_clickable_callback(MAGIC_URL_LOCAL, ' ', 'https://www.dfrobot.com/forum', 'viewtopic.php?f=18&t=2394', ' class="postlink-local"')
Romeo BLE is different to Romeo BLE Quad
Grey.CC
Try this code :
int E1 = 5;
int M1 = 4;
int E2 = 6;
int M2 = 7;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
}
void loop()
{
digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, 200); //PWM Speed Control
analogWrite(E2, 200); //PWM Speed Control
}
}
Note: Like what I said in this post:make_clickable_callback(MAGIC_URL_LOCAL, ' ', 'https://www.dfrobot.com/forum', 'viewtopic.php?f=18&t=2394', ' class="postlink-local"')
Romeo BLE is different to Romeo BLE Quad

2017-01-24 08:41:48 I ran a simple motor control sketch as you said and one motor is always going faster than the other. Is this a case of motor priorities? Thanks.
o.gooberman

2017-01-24 00:03:09 Hi,
it is better to check the hardware first:
Run a simple motor speed control sketch, does the speed same?
Grey.CC
it is better to check the hardware first:
Run a simple motor speed control sketch, does the speed same?
