From b2857fe8b8c429df9049119fda3e7e6908f095cc Mon Sep 17 00:00:00 2001 From: Robert Hanacek Date: Thu, 27 Aug 2020 17:27:24 -0600 Subject: [PATCH 1/2] Invert the direction of left wheel to account for mirrored wheel installation. --- .../SIK_Circuit_5B-RemoteControlRobot.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino b/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino index ab7de5c..32d07ee 100644 --- a/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino +++ b/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino @@ -77,34 +77,34 @@ void loop() Serial.print(" "); Serial.println(distance.toInt()); - if (botDirection == "f") //if the entered direction is forward + if (botDirection == "f") //if the entered direction is forward { rightMotor(200); //drive the right wheel forward - 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 == "b") //if the entered direction is backward { - rightMotor(-200); //drive the right wheel forward - leftMotor(-200); //drive the left wheel forward + rightMotor(-200); //drive the right 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 == "r") //if the entered direction is right { - rightMotor(-200); //drive the right wheel forward - leftMotor(255); //drive the left wheel forward + rightMotor(-200); //drive the right wheel backward + leftMotor(-255); //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 } - else if (botDirection == "l") //if the entered direction is left + 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 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 From 3cc45df3c1a79710d7d9f1a1eb303a64f4e16726 Mon Sep 17 00:00:00 2001 From: Robert Hanacek Date: Fri, 28 Aug 2020 10:09:37 -0600 Subject: [PATCH 2/2] Clarify wheel assembly configuration. Fixes #31 --- .../SIK_Circuit_5B-RemoteControlRobot.ino | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino b/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino index 32d07ee..4117a5d 100644 --- a/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino +++ b/SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino @@ -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 @@ -80,15 +83,15 @@ 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 @@ -96,7 +99,7 @@ void loop() 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 @@ -104,7 +107,7 @@ void loop() 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 @@ -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 @@ -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 @@ -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 } -