Init
Dependents: JetflyerMotorController
Steering.cpp@1:787f4284d968, 2017-07-13 (annotated)
- Committer:
- skrickl
- Date:
- Thu Jul 13 13:42:23 2017 +0000
- Revision:
- 1:787f4284d968
bla
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skrickl | 1:787f4284d968 | 1 | #include "Steering.h" |
skrickl | 1:787f4284d968 | 2 | |
skrickl | 1:787f4284d968 | 3 | Steering::Steering() : _pwm(PIN_PWM_STEERING), _dir(PIN_DIR_STEERING) |
skrickl | 1:787f4284d968 | 4 | { |
skrickl | 1:787f4284d968 | 5 | _pwm.period_ms(20); //needs to be changed!!! |
skrickl | 1:787f4284d968 | 6 | _currentAngle = 0; |
skrickl | 1:787f4284d968 | 7 | _steerAngle = 0; |
skrickl | 1:787f4284d968 | 8 | } |
skrickl | 1:787f4284d968 | 9 | |
skrickl | 1:787f4284d968 | 10 | Steering::~Steering() |
skrickl | 1:787f4284d968 | 11 | { |
skrickl | 1:787f4284d968 | 12 | |
skrickl | 1:787f4284d968 | 13 | } |
skrickl | 1:787f4284d968 | 14 | |
skrickl | 1:787f4284d968 | 15 | void Steering::setSteerAngle(int angle) |
skrickl | 1:787f4284d968 | 16 | { |
skrickl | 1:787f4284d968 | 17 | if (angle > MAX_STEER_ANGLE) angle = MAX_STEER_ANGLE; |
skrickl | 1:787f4284d968 | 18 | if (angle < MIN_STEER_ANGLE) angle = MIN_STEER_ANGLE; |
skrickl | 1:787f4284d968 | 19 | _steerAngle = angle; |
skrickl | 1:787f4284d968 | 20 | } |
skrickl | 1:787f4284d968 | 21 | |
skrickl | 1:787f4284d968 | 22 | void Steering::addToSteerAngle(int angle) |
skrickl | 1:787f4284d968 | 23 | { |
skrickl | 1:787f4284d968 | 24 | int sum = _steerAngle + angle; |
skrickl | 1:787f4284d968 | 25 | setSteerAngle(sum); |
skrickl | 1:787f4284d968 | 26 | } |
skrickl | 1:787f4284d968 | 27 | |
skrickl | 1:787f4284d968 | 28 | int Steering::getSteerAngle() |
skrickl | 1:787f4284d968 | 29 | { |
skrickl | 1:787f4284d968 | 30 | return _steerAngle; |
skrickl | 1:787f4284d968 | 31 | } |
skrickl | 1:787f4284d968 | 32 | |
skrickl | 1:787f4284d968 | 33 | int Steering::readCurrentAngle() |
skrickl | 1:787f4284d968 | 34 | { |
skrickl | 1:787f4284d968 | 35 | _currentAngle = 5; //replace by reading the sensor |
skrickl | 1:787f4284d968 | 36 | return _currentAngle; |
skrickl | 1:787f4284d968 | 37 | } |
skrickl | 1:787f4284d968 | 38 | |
skrickl | 1:787f4284d968 | 39 | int Steering::getCurrentAngle() |
skrickl | 1:787f4284d968 | 40 | { |
skrickl | 1:787f4284d968 | 41 | return _currentAngle; |
skrickl | 1:787f4284d968 | 42 | } |
skrickl | 1:787f4284d968 | 43 | |
skrickl | 1:787f4284d968 | 44 | void Steering::turn(float percentage) |
skrickl | 1:787f4284d968 | 45 | { |
skrickl | 1:787f4284d968 | 46 | //write to motor -1 ,1 direction |
skrickl | 1:787f4284d968 | 47 | _pwm.write(abs(percentage)/100.0); |
skrickl | 1:787f4284d968 | 48 | if (percentage < 0) _dir.write(0); |
skrickl | 1:787f4284d968 | 49 | else _dir.write(1); |
skrickl | 1:787f4284d968 | 50 | } |