DriverTest


#1

Hi!
I have tried the DCMotorDriverTest for Arduino:

#include “MeOrion.h”

MeDCMotor motor1(PORT_1);

MeDCMotor motor2(PORT_2);

MeDCMotor motor3(M1);

MeDCMotor motor4(M2);

uint8_t motorSpeed = 100;

void setup()
{
}

void loop()
{
motor1.run(motorSpeed); /* value: between -255 and 255. /
motor2.run(motorSpeed); /
value: between -255 and 255. */
motor3.run(motorSpeed);
motor4.run(motorSpeed);
delay(2000);
motor1.stop();
motor2.stop();
motor3.stop();
motor4.stop();
delay(100);
motor1.run(-motorSpeed);
motor2.run(-motorSpeed);
motor3.run(-motorSpeed);
motor4.run(-motorSpeed);
delay(2000);
motor1.stop();
motor2.stop();
motor3.stop();
motor4.stop();
delay(2000);
}

But when I upload the code to the mbot the mbot don’t go straight on but will turn turn left and turn to right.

I have changed the code to:

#include “MeOrion.h”

MeDCMotor motor1(PORT_1);

MeDCMotor motor2(PORT_2);

MeDCMotor motor3(M1);

MeDCMotor motor4(M2);

uint8_t motorSpeed = 100;

void setup()
{
}

void loop()
{
motor1.run(motorSpeed); /* value: between -255 and 255. /
motor2.run(motorSpeed); /
value: between -255 and 255. */
motor3.run(motorSpeed);
motor4.run(-motorSpeed);
delay(2000);
motor1.stop();
motor2.stop();
motor3.stop();
motor4.stop();
delay(100);
motor1.run(-motorSpeed);
motor2.run(-motorSpeed);
motor3.run(-motorSpeed);
motor4.run(motorSpeed);
delay(2000);
motor1.stop();
motor2.stop();
motor3.stop();
motor4.stop();
delay(2000);
}

then the mbot will go straight on.
Also I don’t know why I need motor1 and motor2 because the mbot will work when I use only motor3 and motor4.

Hope somebody can help me.
kindly regards


#2

Are you only using two motors?


#3

Hi.
Thanks for the answer.
My mbot use only two motors.
I have here the standard edition.
Kindly regards


#4

I notice that you are using the Orion.h header file. May I assume that you are using the mBot Starter kit?

Try this code:

#include <MeOrion.h>

MeDCMotor Motor1(9);
MeDCMotor Motor2(10);

const int motor_speed = 100;

void setup(){
}

void loop(){
    Motor1.run(motor_speed);
    Motor2.run(-motor_speed);
    delay(2);
    Motor1.run(0);
    Motor2.run(0);
    delay(0.1);
    Motor1.run(-motor_speed);
    Motor2.run(motor_speed);
    delay(2);
    Motor1.run(0);
    Motor2.run(0);
    delay(2);
    }

void _loop(){
}

#5

Thanks a lot for your answer. I will try it but why I must use -motor_speed at Motor2 and at the same time motor_speed at Motor1?
Thanks for an explanation.
kindly regards.


#6

The biggest reason for negating one of the values is that the motors are identical with regard to the direction they turn. If you give both motors a positive value, they will both turn in a clockwise rotation which will simply make the robot spin in place. :slight_smile:


#7

Hi Haiflosse,
The motors are mirror-installed. The speed direction should be opposite for move forward/backward.