A class for calculating steering angle calculations based on current and desired heading and specified intercept distance along the new path.
Steering.h@0:a3b128cdb78b, 2011-04-27 (annotated)
- Committer:
- shimniok
- Date:
- Wed Apr 27 18:55:38 2011 +0000
- Revision:
- 0:a3b128cdb78b
Initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a3b128cdb78b | 1 | |
shimniok | 0:a3b128cdb78b | 2 | #define PI 3.141592653589 |
shimniok | 0:a3b128cdb78b | 3 | |
shimniok | 0:a3b128cdb78b | 4 | /** A class for managing steering angle calculations based on current and desired heading |
shimniok | 0:a3b128cdb78b | 5 | * and specified intercept distance along the new path. |
shimniok | 0:a3b128cdb78b | 6 | * |
shimniok | 0:a3b128cdb78b | 7 | * See Notebook entry: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/ |
shimniok | 0:a3b128cdb78b | 8 | */ |
shimniok | 0:a3b128cdb78b | 9 | class Steering |
shimniok | 0:a3b128cdb78b | 10 | { |
shimniok | 0:a3b128cdb78b | 11 | public: |
shimniok | 0:a3b128cdb78b | 12 | /** create a new steering calculator |
shimniok | 0:a3b128cdb78b | 13 | * |
shimniok | 0:a3b128cdb78b | 14 | * @param wheelbase vehicle wheelbase |
shimniok | 0:a3b128cdb78b | 15 | * @param track vehicle track width |
shimniok | 0:a3b128cdb78b | 16 | * @param intercept new course intercept distance |
shimniok | 0:a3b128cdb78b | 17 | */ |
shimniok | 0:a3b128cdb78b | 18 | Steering(float wheelbase, float track); |
shimniok | 0:a3b128cdb78b | 19 | |
shimniok | 0:a3b128cdb78b | 20 | /** set intercept distance |
shimniok | 0:a3b128cdb78b | 21 | * @param intercept distance along new course at which turn arc will intercept |
shimniok | 0:a3b128cdb78b | 22 | */ |
shimniok | 0:a3b128cdb78b | 23 | void setIntercept(float intercept); |
shimniok | 0:a3b128cdb78b | 24 | |
shimniok | 0:a3b128cdb78b | 25 | /** convert course change to average steering angle |
shimniok | 0:a3b128cdb78b | 26 | * assumes Ackerman steering, with track and wheelbase |
shimniok | 0:a3b128cdb78b | 27 | * and course intercept distance specified. |
shimniok | 0:a3b128cdb78b | 28 | * |
shimniok | 0:a3b128cdb78b | 29 | * See notebook: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/ |
shimniok | 0:a3b128cdb78b | 30 | * |
shimniok | 0:a3b128cdb78b | 31 | * @param theta relative bearing of the new course |
shimniok | 0:a3b128cdb78b | 32 | * @returns steering angle in degrees |
shimniok | 0:a3b128cdb78b | 33 | */ |
shimniok | 0:a3b128cdb78b | 34 | float calcSA(float theta); |
shimniok | 0:a3b128cdb78b | 35 | |
shimniok | 0:a3b128cdb78b | 36 | private: |
shimniok | 0:a3b128cdb78b | 37 | |
shimniok | 0:a3b128cdb78b | 38 | inline static float angle_radians(float deg) {return (PI/180.0)*deg;} |
shimniok | 0:a3b128cdb78b | 39 | |
shimniok | 0:a3b128cdb78b | 40 | inline static float angle_degrees(float rad) {return (180/PI)*rad;} |
shimniok | 0:a3b128cdb78b | 41 | |
shimniok | 0:a3b128cdb78b | 42 | float _wheelbase; |
shimniok | 0:a3b128cdb78b | 43 | float _track; |
shimniok | 0:a3b128cdb78b | 44 | float _intercept; |
shimniok | 0:a3b128cdb78b | 45 | }; |