Go Down

Topic: Adding Line Followers to Code (Read 1 time) previous topic - next topic


Ok. I see what you're saying about the motor speeds. m[ii]->setSpeed(255); seems to control both motors
It only controls motor ii where ii is a variable that is stepped through all your motors by the for statement in your code:
Code: [Select]
for(int ii = 0; ii < num_motors; ii++){
The line
Code: [Select]
Wicked_DCMotor *m[] = {&motor1, &motor2};
means that m[0] is motor1 and m[1] is motor 2. So to make your code much less confusing do this:
Code: [Select]
Wicked_DCMotor leftMotor(M1);
Wicked_DCMotor rightMotor(M2);

Wicked_DCMotor *m[] = {&leftMotor, &rightMotor};

const byte leftMotorID = 0;
const byte rightMotorID = 1;

Of course I don't know which motor is which on your robot so I might have them backwards but you get the idea. After doing that if you want to set the speed of the left motor to 255 you can do:
Code: [Select]
instead of
Code: [Select]
It accomplishes the same thing but is more readable.

I need them to operate separately, like in the RedBot code.
Yes, by controlling the speed of each motor you can steer your robot to make it stay on the line. If the right motor is set to a higher speed than the left motor the robot turns left.


You still have not explained why reading the sensors is dependent on the number of motors. There are some things that need to be in the for loop that iterates over the motor, and some things that do NOT belong in that loop. You need to understand which is which.
The art of getting good answers lies in asking good questions.

Go Up