Mark Jones
/
RenBuggy_Servo
The programme shows some of the features of the RenBuggyServo library in action.
main.cpp@1:1a5db4892449, 2014-03-13 (annotated)
- Committer:
- Markatron
- Date:
- Thu Mar 13 07:31:28 2014 +0000
- Revision:
- 1:1a5db4892449
- Parent:
- 0:40e8ea905308
Finished adding functionality for use of an encoder.;
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 | 1:1a5db4892449 | 12 | Car myCar(P1_26, P1_24, 16, 16.65f, P0_7); |
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 | myCar.setDirection(0); |
Markatron | 1:1a5db4892449 | 32 | |
Markatron | 1:1a5db4892449 | 33 | myCar.forwards(7); |
Markatron | 0:40e8ea905308 | 34 | myCar.setDirection(45); |
Markatron | 1:1a5db4892449 | 35 | myCar.forwards(20); |
Markatron | 1:1a5db4892449 | 36 | myCar.setDirection(-30); |
Markatron | 1:1a5db4892449 | 37 | myCar.forwards(20); |
Markatron | 0:40e8ea905308 | 38 | } |