car chassis
Dependencies: Servo mbed-rtos mbed
engine.cpp@0:ce6055872f4e, 2015-08-02 (annotated)
- Committer:
- mariob
- Date:
- Sun Aug 02 12:55:33 2015 +0000
- Revision:
- 0:ce6055872f4e
- Child:
- 1:79b1ee0f97ef
first commit: new car ECU
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mariob | 0:ce6055872f4e | 1 | //#include "Servo.h" |
mariob | 0:ce6055872f4e | 2 | |
mariob | 0:ce6055872f4e | 3 | /* |
mariob | 0:ce6055872f4e | 4 | void thread_ecm (void const *args) |
mariob | 0:ce6055872f4e | 5 | { |
mariob | 0:ce6055872f4e | 6 | //read signals |
mariob | 0:ce6055872f4e | 7 | float power = read_engine_power(); //[0, 100] |
mariob | 0:ce6055872f4e | 8 | uint8 direction = read_engine_direction(); //[0, 1] |
mariob | 0:ce6055872f4e | 9 | float angle = read_steering_angle(); //[0, 100] |
mariob | 0:ce6055872f4e | 10 | //use them |
mariob | 0:ce6055872f4e | 11 | if ((power>=0.0) && (power<=100.0)) |
mariob | 0:ce6055872f4e | 12 | engine_power = power/100.0; |
mariob | 0:ce6055872f4e | 13 | if ((direction==0) || (direction==1)) |
mariob | 0:ce6055872f4e | 14 | engine_direction = direction; |
mariob | 0:ce6055872f4e | 15 | if ((angle<=100.0) && (angle>=0.0)) |
mariob | 0:ce6055872f4e | 16 | steering_servo = angle/100.0; |
mariob | 0:ce6055872f4e | 17 | //wait |
mariob | 0:ce6055872f4e | 18 | Thread::wait(100); |
mariob | 0:ce6055872f4e | 19 | } |
mariob | 0:ce6055872f4e | 20 | */ |
mariob | 0:ce6055872f4e | 21 | |
mariob | 0:ce6055872f4e | 22 | |
mariob | 0:ce6055872f4e | 23 | /* |
mariob | 0:ce6055872f4e | 24 | |
mariob | 0:ce6055872f4e | 25 | Servo steering_servo(p21); |
mariob | 0:ce6055872f4e | 26 | PwmOut engine_power(p22); |
mariob | 0:ce6055872f4e | 27 | |
mariob | 0:ce6055872f4e | 28 | void thread_steering (void const *args); |
mariob | 0:ce6055872f4e | 29 | void thread_engine (void const *args); |
mariob | 0:ce6055872f4e | 30 | |
mariob | 0:ce6055872f4e | 31 | void init_hw () |
mariob | 0:ce6055872f4e | 32 | { |
mariob | 0:ce6055872f4e | 33 | steering_servo.calibrate(0.0005, 45.0); |
mariob | 0:ce6055872f4e | 34 | |
mariob | 0:ce6055872f4e | 35 | engine_power.period(0.020); //20ms |
mariob | 0:ce6055872f4e | 36 | engine_power = 0; //off |
mariob | 0:ce6055872f4e | 37 | } |
mariob | 0:ce6055872f4e | 38 | */ |