Created
July 5, 2016 02:55
-
-
Save GreenMoonArt/1e78b89e2f11b29be925469c3fb82a02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* YourDuino Basic Robot Kit V2 Motor Speed Test | |
http://yourduino.com/sunshop2/index.php?l=product_detail&p=400 | |
source: https://arduino-info.wikispaces.com/YourDuino-Basic-Robot-Kit-Software-Version2 | |
- WHAT IT DOES: | |
- Runs the robot motors at different speeds. Helps adjust Right-Left offsets | |
- SEE the comments after "//" on each line below | |
This test sketch will run the robot in slow, medium and fast speeds. You should place it on a smooth floor if possible. | |
Carpet, especially thick carpet will slow or stop this robot. If you must run it on some carpet, you may have to change the | |
MoveSpeed values to be higher, like SlowMoveSpeed 300, MediumMoveSpeed 360, FastMovespeed 390. But it will only run really | |
well on a smooth floor. | |
You can adjust the right VS left motor speeds to try to get the robot to move straight ahead. You can hold the robot in both hands, | |
holding the RESET button on the right side of the RoboRED pressed until you put the robot down. Also make sure the caster wheel is | |
pointing straight when you start. | |
- CONNECTIONS: | |
Pins 9 (Motor1 PWM) and 10 (Motor2 PWM) are predefined, unchangeable | |
// Label--Arduino Pin-- Motor Driver Pin | |
Motor1A pin 8 // INA | |
Motor1B pin 7 // INB | |
Motor2C pin 6 // INC | |
Motor2D pin 5 // IND | |
- V2.10 11/10/2014 | |
Questions: terry@yourduino.com */ | |
/*-----( Import needed libraries )-----*/ | |
#include <YD_MotorDriver1.h> // For control of the two DC Motors | |
/*-----( Declare Constants and Pin Numbers )-----*/ | |
// NOTE: Pins 9 (Motor1) and 10 (Motor2) are predefined, unchangeable | |
#define Motor1A 8 | |
#define Motor1B 7 | |
#define Motor2C 6 | |
#define Motor2D 5 | |
#define StartMoveSpeed 200 // Motor Driver value for start of motion | |
#define SlowMoveSpeed 280 | |
#define SlowMoveAdjust 5 // Adjust for straight move: - Left + Right?? | |
#define MediumMoveSpeed 300 | |
#define MediumMoveAdjust 5 // Adjust for straight move: - Left + Right | |
#define FastMoveSpeed 350 | |
#define FastMoveAdjust 5 // Adjust for straight move: - Left + Right | |
/*-----( Declare objects )-----*/ | |
YD_MotorDriver1 RobotDriver(Motor1A,Motor1B,Motor2C,Motor2D); // Set pins | |
void setup() /******************* SETUP: RUNS ONCE *****************/ | |
{ | |
Serial.begin(115200); | |
delay(1000); | |
Serial.println("YourDuino Robot Kit V2 Motor Speed Test"); | |
//--NOTE: Motor Pins set to OUTPUT by their libraries | |
RobotDriver.init(); | |
}//--(end setup )--- | |
/************** LOOP: RUNS CONSTANTLY **************************/ | |
void loop() | |
{ | |
Serial.println("Forward Slow Speed"); | |
ForwardSlow(); | |
delay(5000); | |
Stop(); | |
Serial.println("---STOP---"); | |
delay(5000); | |
Serial.println("Forward Medium Speed"); | |
ForwardMedium(); | |
delay(5000); | |
Stop(); | |
Serial.println("---STOP---"); | |
delay(5000); | |
Serial.println("Forward Fast Speed"); | |
ForwardFast(); | |
delay(5000); | |
Stop(); | |
Serial.println("---STOP---"); | |
delay(10000); | |
Serial.println("---END---"); | |
}//--(end main loop )--- | |
/*----------------( Declare User-written Functions )---------------*/ | |
//------( MOTOR CONTROL FUNCTIONS )---------------- | |
void ForwardSlow() | |
{ | |
RobotDriver.Motor1Speed(SlowMoveSpeed + SlowMoveAdjust); | |
RobotDriver.Motor2Speed(SlowMoveSpeed - SlowMoveAdjust); | |
} | |
/*---------------------------*/ | |
void ForwardMedium() | |
{ | |
RobotDriver.Motor1Speed(MediumMoveSpeed + MediumMoveAdjust); | |
RobotDriver.Motor2Speed(MediumMoveSpeed - MediumMoveAdjust); | |
} | |
/*---------------------------*/ | |
void ForwardFast() | |
{ | |
RobotDriver.Motor1Speed(FastMoveSpeed + FastMoveAdjust); | |
RobotDriver.Motor2Speed(FastMoveSpeed - FastMoveAdjust); | |
} | |
/*---------------------------*/ | |
void BackwardSlow(int HowMuch) | |
{ | |
RobotDriver.Motor1Speed(- SlowMoveSpeed ); | |
RobotDriver.Motor2Speed(- SlowMoveSpeed ); | |
delay(HowMuch); | |
Stop(); | |
} | |
/*---------------------------*/ | |
void BackwardMedium(int HowMuch) | |
{ | |
RobotDriver.Motor1Speed(- MediumMoveSpeed); | |
RobotDriver.Motor2Speed(- MediumMoveSpeed); | |
delay(HowMuch); | |
Stop(); | |
} | |
/*---------------------------*/ | |
void BackwardFast(int HowMuch) | |
{ | |
RobotDriver.Motor1Speed(- FastMoveSpeed); | |
RobotDriver.Motor2Speed(- FastMoveSpeed); | |
delay(HowMuch); | |
Stop(); | |
} | |
/*---------------------------*/ | |
void Stop() | |
{ | |
RobotDriver.Motor1Speed(0); | |
RobotDriver.Motor2Speed(0); | |
} | |
/*---------------------------*/ | |
void SpinLeft(int HowMuch) | |
{ | |
RobotDriver.Motor1Speed(MediumMoveSpeed); | |
RobotDriver.Motor2Speed(- MediumMoveSpeed); | |
delay(HowMuch); | |
Stop(); | |
} | |
/*---------------------------*/ | |
void SpinRight(int HowMuch) | |
{ | |
RobotDriver.Motor1Speed(MediumMoveSpeed); | |
RobotDriver.Motor2Speed(- MediumMoveSpeed); | |
delay(HowMuch); | |
Stop(); | |
} | |
/*---------------------------*/ | |
//*********( THE END )*********** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment