Mark Jones
/
RenBuggy_Servo
The programme shows some of the features of the RenBuggyServo library in action.
main.cpp@0:40e8ea905308, 2014-03-07 (annotated)
- Committer:
- Markatron
- Date:
- Fri Mar 07 08:01:42 2014 +0000
- Revision:
- 0:40e8ea905308
- Child:
- 1:1a5db4892449
This programme shows some of the features of the RenBuggyServo library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Markatron | 0:40e8ea905308 | 1 | /******************************************************************************* |
Markatron | 0:40e8ea905308 | 2 | * This program demonstrates how to drive the RenBuggy_Servo |
Markatron | 0:40e8ea905308 | 3 | * using the Car library. |
Markatron | 0:40e8ea905308 | 4 | * |
Markatron | 0:40e8ea905308 | 5 | * Mark Jones |
Markatron | 0:40e8ea905308 | 6 | * V1.0 05/03/2014 |
Markatron | 0:40e8ea905308 | 7 | *******************************************************************************/ |
Markatron | 0:40e8ea905308 | 8 | |
Markatron | 0:40e8ea905308 | 9 | #include "mbed.h" |
Markatron | 0:40e8ea905308 | 10 | #include "Car.h" |
Markatron | 0:40e8ea905308 | 11 | |
Markatron | 0:40e8ea905308 | 12 | Car myCar(P1_25, P1_24); |
Markatron | 0:40e8ea905308 | 13 | |
Markatron | 0:40e8ea905308 | 14 | // Main entry point of application. |
Markatron | 0:40e8ea905308 | 15 | int main() { |
Markatron | 0:40e8ea905308 | 16 | |
Markatron | 0:40e8ea905308 | 17 | const int SERVO_PWM = 1500; // 1500 = centre. |
Markatron | 0:40e8ea905308 | 18 | const int SERVO_PWM_PERIOD = 2000; |
Markatron | 0:40e8ea905308 | 19 | const int SERVO_PWM_RANGE = 500; // + or - 500 microseconds. |
Markatron | 0:40e8ea905308 | 20 | const float SERVO_DEGREES_RANGE = 45.0; // + or - from centre is full right/left. |
Markatron | 0:40e8ea905308 | 21 | |
Markatron | 0:40e8ea905308 | 22 | const int MOTOR_PWM = 20000; |
Markatron | 0:40e8ea905308 | 23 | const int MOTOR_PERIOD = 20000; |
Markatron | 0:40e8ea905308 | 24 | |
Markatron | 0:40e8ea905308 | 25 | // Configure the servo and motor before use. |
Markatron | 0:40e8ea905308 | 26 | myCar.configureServo_us(SERVO_PWM, SERVO_PWM_PERIOD, |
Markatron | 0:40e8ea905308 | 27 | SERVO_PWM_RANGE, SERVO_DEGREES_RANGE); |
Markatron | 0:40e8ea905308 | 28 | |
Markatron | 0:40e8ea905308 | 29 | myCar.configureMotor_us(MOTOR_PWM, MOTOR_PERIOD); |
Markatron | 0:40e8ea905308 | 30 | |
Markatron | 0:40e8ea905308 | 31 | // Drive the RenBuggy! |
Markatron | 0:40e8ea905308 | 32 | myCar.setDirection(0); |
Markatron | 0:40e8ea905308 | 33 | wait(1); |
Markatron | 0:40e8ea905308 | 34 | myCar.forwards(); |
Markatron | 0:40e8ea905308 | 35 | wait(4); |
Markatron | 0:40e8ea905308 | 36 | myCar.setDirection(45); |
Markatron | 0:40e8ea905308 | 37 | wait(8); |
Markatron | 0:40e8ea905308 | 38 | myCar.setDirection(0); |
Markatron | 0:40e8ea905308 | 39 | wait(4); |
Markatron | 0:40e8ea905308 | 40 | myCar.setDirection(-45); |
Markatron | 0:40e8ea905308 | 41 | wait(8); |
Markatron | 0:40e8ea905308 | 42 | myCar.stop(); |
Markatron | 0:40e8ea905308 | 43 | } |