Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
Actuators/Steering/Steering.h@0:826c6171fc1b, 2012-06-20 (annotated)
- Committer:
- shimniok
- Date:
- Wed Jun 20 14:57:48 2012 +0000
- Revision:
- 0:826c6171fc1b
Updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:826c6171fc1b | 1 | |
shimniok | 0:826c6171fc1b | 2 | #define PI 3.141592653589 |
shimniok | 0:826c6171fc1b | 3 | |
shimniok | 0:826c6171fc1b | 4 | /** A class for managing steering angle calculations based on current and desired heading |
shimniok | 0:826c6171fc1b | 5 | * and specified intercept distance along the new path. |
shimniok | 0:826c6171fc1b | 6 | * |
shimniok | 0:826c6171fc1b | 7 | * See Notebook entry: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/ |
shimniok | 0:826c6171fc1b | 8 | */ |
shimniok | 0:826c6171fc1b | 9 | class Steering |
shimniok | 0:826c6171fc1b | 10 | { |
shimniok | 0:826c6171fc1b | 11 | public: |
shimniok | 0:826c6171fc1b | 12 | /** create a new steering calculator |
shimniok | 0:826c6171fc1b | 13 | * |
shimniok | 0:826c6171fc1b | 14 | * @param wheelbase vehicle wheelbase |
shimniok | 0:826c6171fc1b | 15 | * @param track vehicle track width |
shimniok | 0:826c6171fc1b | 16 | * @param intercept new course intercept distance |
shimniok | 0:826c6171fc1b | 17 | */ |
shimniok | 0:826c6171fc1b | 18 | Steering(float wheelbase, float track); |
shimniok | 0:826c6171fc1b | 19 | |
shimniok | 0:826c6171fc1b | 20 | /** set intercept distance |
shimniok | 0:826c6171fc1b | 21 | * @param intercept distance along new course at which turn arc will intercept |
shimniok | 0:826c6171fc1b | 22 | */ |
shimniok | 0:826c6171fc1b | 23 | void setIntercept(float intercept); |
shimniok | 0:826c6171fc1b | 24 | |
shimniok | 0:826c6171fc1b | 25 | /** convert course change to average steering angle |
shimniok | 0:826c6171fc1b | 26 | * assumes Ackerman steering, with track and wheelbase |
shimniok | 0:826c6171fc1b | 27 | * and course intercept distance specified. |
shimniok | 0:826c6171fc1b | 28 | * |
shimniok | 0:826c6171fc1b | 29 | * See notebook: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/ |
shimniok | 0:826c6171fc1b | 30 | * |
shimniok | 0:826c6171fc1b | 31 | * @param theta relative bearing of the new course |
shimniok | 0:826c6171fc1b | 32 | * @returns steering angle in degrees |
shimniok | 0:826c6171fc1b | 33 | */ |
shimniok | 0:826c6171fc1b | 34 | float calcSA(float theta); |
shimniok | 0:826c6171fc1b | 35 | |
shimniok | 0:826c6171fc1b | 36 | /** convert course change to average steering angle |
shimniok | 0:826c6171fc1b | 37 | * assumes Ackerman steering, with track and wheelbase |
shimniok | 0:826c6171fc1b | 38 | * and course intercept distance specified. Also, |radius| of turn is limited to limit |
shimniok | 0:826c6171fc1b | 39 | * |
shimniok | 0:826c6171fc1b | 40 | * See notebook: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/ |
shimniok | 0:826c6171fc1b | 41 | * |
shimniok | 0:826c6171fc1b | 42 | * @param theta relative bearing of the new course |
shimniok | 0:826c6171fc1b | 43 | * @param limit is the limit of the turn circle radius (absolute value) |
shimniok | 0:826c6171fc1b | 44 | * @returns steering angle in degrees |
shimniok | 0:826c6171fc1b | 45 | */ |
shimniok | 0:826c6171fc1b | 46 | float calcSA(float theta, float limit); |
shimniok | 0:826c6171fc1b | 47 | |
shimniok | 0:826c6171fc1b | 48 | /** compute steering angle based on pure pursuit algorithm |
shimniok | 0:826c6171fc1b | 49 | */ |
shimniok | 0:826c6171fc1b | 50 | float purePursuitSA(float hdg, float Bx, float By, float Ax, float Ay, float Bx, float By); |
shimniok | 0:826c6171fc1b | 51 | |
shimniok | 0:826c6171fc1b | 52 | /** Compute cross track error given last waypoint, next waypoint, and robot coordinates |
shimniok | 0:826c6171fc1b | 53 | * @returns cross track error |
shimniok | 0:826c6171fc1b | 54 | */ |
shimniok | 0:826c6171fc1b | 55 | float crossTrack(float Bx, float By, float Ax, float Ay, float Bx, float By); |
shimniok | 0:826c6171fc1b | 56 | |
shimniok | 0:826c6171fc1b | 57 | private: |
shimniok | 0:826c6171fc1b | 58 | |
shimniok | 0:826c6171fc1b | 59 | inline static float angle_radians(float deg) {return (PI/180.0)*deg;} |
shimniok | 0:826c6171fc1b | 60 | |
shimniok | 0:826c6171fc1b | 61 | inline static float angle_degrees(float rad) {return (180/PI)*rad;} |
shimniok | 0:826c6171fc1b | 62 | |
shimniok | 0:826c6171fc1b | 63 | float _wheelbase; |
shimniok | 0:826c6171fc1b | 64 | float _track; |
shimniok | 0:826c6171fc1b | 65 | float _intercept; |
shimniok | 0:826c6171fc1b | 66 | }; |