Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert the direction of left wheel to account for mirrored wheel installation. #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Clarify wheel assembly configuration.
Fixes #31
  • Loading branch information
bitmole committed Aug 28, 2020
commit 3cc45df3c1a79710d7d9f1a1eb303a64f4e16726
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const int turnTime = 8; //this is the number of milliseconds that it take
//surface that your driving on, and fluctuations in the power to the motors.
//You can change the driveTime and turnTime to make them more accurate

enum Mirror { LEFT, RIGHT };
Mirror mirroredWheel = LEFT; //the wheel that's "flipped" in the mirror-image assembly

String botDirection; //the direction that the robot will drive in (this change which direction the two motors spin in)
String distance; //the distance to travel in each direction

Expand Down Expand Up @@ -80,31 +83,31 @@ void loop()
if (botDirection == "f") //if the entered direction is forward
{
rightMotor(200); //drive the right wheel forward
leftMotor(-200); //drive the left wheel backward
leftMotor(200); //drive the left wheel forward
delay(driveTime * distance.toInt()); //drive the motors long enough travel the entered distance
rightMotor(0); //turn the right motor off
leftMotor(0); //turn the left motor off
}
else if (botDirection == "b") //if the entered direction is backward
else if (botDirection == "b") //if the entered direction is backward
{
rightMotor(-200); //drive the right wheel backward
leftMotor(200); //drive the left wheel forward
leftMotor(-200); //drive the left wheel backward
delay(driveTime * distance.toInt()); //drive the motors long enough travel the entered distance
rightMotor(0); //turn the right motor off
leftMotor(0); //turn the left motor off
}
else if (botDirection == "r") //if the entered direction is right
{
rightMotor(-200); //drive the right wheel backward
leftMotor(-255); //drive the left wheel backward
leftMotor(255); //drive the left wheel forward
delay(turnTime * distance.toInt()); //drive the motors long enough turn the entered distance
rightMotor(0); //turn the right motor off
leftMotor(0); //turn the left motor off
}
else if (botDirection == "l") //if the entered direction is left
{
rightMotor(255); //drive the right wheel forward
leftMotor(200); //drive the left wheel forward
leftMotor(-200); //drive the left wheel backward
delay(turnTime * distance.toInt()); //drive the motors long enough turn the entered distance
rightMotor(0); //turn the right motor off
leftMotor(0); //turn the left motor off
Expand All @@ -120,6 +123,10 @@ void loop()
/********************************************************************************/
void rightMotor(int motorSpeed) //function for driving the right motor
{
if (mirroredWheel == RIGHT) {
motorSpeed = -motorSpeed;
}

if (motorSpeed > 0) //if the motor should drive forward (positive speed)
{
digitalWrite(AIN1, HIGH); //set pin 1 to high
Expand All @@ -141,6 +148,10 @@ void rightMotor(int motorSpeed) //function for driving the
/********************************************************************************/
void leftMotor(int motorSpeed) //function for driving the left motor
{
if (mirroredWheel == LEFT) {
motorSpeed = -motorSpeed;
}

if (motorSpeed > 0) //if the motor should drive forward (positive speed)
{
digitalWrite(BIN1, HIGH); //set pin 1 to high
Expand All @@ -158,4 +169,3 @@ void leftMotor(int motorSpeed) //function for driving the
}
analogWrite(PWMB, abs(motorSpeed)); //now that the motor direction is set, drive it at the entered speed
}