Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:2bab3a0bc3bc
- Parent:
- 0:59d25bb7f825
- Child:
- 2:1feae3cb6731
diff -r 59d25bb7f825 -r 2bab3a0bc3bc main.cpp
--- a/main.cpp Wed Feb 04 16:55:27 2015 +0000
+++ b/main.cpp Wed Feb 18 14:57:56 2015 +0000
@@ -14,33 +14,28 @@
PwmOut motor_r (PTE29);
//LED to test
-DigitalOut myled(LED_RED);
-/*
-Pivot Right: //Change duties for speed
-motor_rf=0;
-motor_rb=0;
-motor_lf=1;
-motor_lb=0;
-Pivot Left: //Change duties for speed
-motor_rf=1;
-motor_rb=0;
-motor_lf=0;
-motor_lb=0;
-Forwards: //Change duties for speed & direction
-motor_rf=1;
-motor_rb=0;
-motor_lf=1;
-motor_lb=0;
-Backwards: //Change duties for speed & direction
-motor_rf=0;
-motor_rb=1;
-motor_lf=0;
-motor_lb=1;
-*/
-void set_direction( int nature_of_direction, float speed)
+DigitalOut led(LED_RED);
+
+void set_direction( bool direction, float speed, float angle)
{
- switch(nature_of_direction) {
- case "forward": {
+ /* *******************Example Use*****************
+ set_direction(1, 0.5, 0); //This would set the robot to go forward, at half speed, straight
+
+ set_directin(1, 0.8, 0.2); //this would set robot to go forward, at 100% to the right and 60% to the left (turn right)
+
+ set_direction(0, 0.3, 0.7); //robot back, 100% rightmotor; 0%left (technically -40%, but 0% is min)
+
+ set_direction(1, 0.5, 0.5); // robot pivots forward, to the right, full speed (100% duty right ; 0% duty left)
+
+ set_direction(1, 0.5, -0.5); //robot pivots forward, to the left, full speed (0% duty right ; 100% duty left)
+
+ set_direction(1, 0.3, 0.5); //robot pivots forard, to the right , at 80% speed (80% right; 0% left)
+
+ set_direction(1, -0.3, 0.5); //robot pivotrs foward, to the right, AT 20% SPEED (20%, 0%)
+
+ */
+ switch(direction) {
+ case '1': { //forward
motor_r.write(speed + angle); //where angle can be postive and negative and will TURN the robot
motor_l.write(speed - angle);
//if turning left, you'd make the angle postive (right motor goes faster left motor goes slwoer)
@@ -49,7 +44,7 @@
motor_lf=1;
motor_lb=0;
}
- case "backwards": {
+ case '0': { //backward
motor_r.write(speed + angle); //where angle can be postive and negative and will TURN the robot
motor_l.write(speed - angle);
//if turning left, you'd make the angle postive (right motor goes faster left motor goes slwoer)
@@ -58,24 +53,6 @@
motor_lf=0;
motor_lb=1;
}
- case "pivot right": {
- motor_r.write(0); //motor doesn't need to be enabled
- motor_l.write(speed);
-
- motor_rf=0;
- motor_rb=0;
- motor_lf=1;
- motor_lb=0;
- }
- case "pivot left": {
- motor_r.write(speed);
- motor_l.write(0); //motor doesn't need to be enabled
-
- motor_rf=1;
- motor_rb=0;
- motor_lf=0;
- motor_lb=0;
- }
}
}
@@ -92,6 +69,40 @@
motor_lb=0;
+
+ while(1) {
+ wait(2);
+ led = !led;
+ set_direction(1, 0.5, 0); //This would set the robot to go forward, at half speed, straight
+
+ wait(2);
+ led = !led;
+ set_direction(1, 0.8, 0.2); //this would set robot to go forward, at 100% to the right and 60% to the left (turn right)
+
+ wait(2);
+ led = !led;
+ set_direction(0, 0.3, 0.7); //robot back, 100% rightmotor; 0%left (technically -40%, but 0% is min)
+
+ wait(2);
+ led = !led;
+ set_direction(1, 0.5, 0.5); // robot pivots forward, to the right, full speed (100% duty right ; 0% duty left)
+
+ wait(2);
+ led = !led;
+ set_direction(1, 0.5, -0.5); //robot pivots forward, to the left, full speed (0% duty right ; 100% duty left)
+
+ wait(2);
+ led = !led;
+ set_direction(1, 0.3, 0.5); //robot pivots forard, to the right , at 80% speed (80% right; 0% left)
+
+ wait(2);
+ led = !led;
+ set_direction(1, -0.3, 0.5); //robot pivotrs foward, to the right, AT 20% SPEED (20%, 0%)
+ }
+
+
+ /* working demo
+
while(1) { //infinite loop
//***********************************************
myled = !myled;
@@ -184,7 +195,8 @@
motor_lb=0; //go forwards
//
wait(4);
+ }
+ */
- }
}