Init

Dependents:   JetflyerMotorController

Files at this revision

API Documentation at this revision

Comitter:
skrickl
Date:
Thu Jul 13 13:42:23 2017 +0000
Parent:
0:21d9efc7ecb6
Commit message:
bla

Changed in this revision

Steering.cpp Show annotated file Show diff for this revision Revisions of this file
Steering.h Show annotated file Show diff for this revision Revisions of this file
Sterring.cpp Show diff for this revision Revisions of this file
diff -r 21d9efc7ecb6 -r 787f4284d968 Steering.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Steering.cpp	Thu Jul 13 13:42:23 2017 +0000
@@ -0,0 +1,50 @@
+#include "Steering.h"
+
+Steering::Steering() : _pwm(PIN_PWM_STEERING), _dir(PIN_DIR_STEERING)
+{
+    _pwm.period_ms(20); //needs to be changed!!!
+    _currentAngle = 0;
+    _steerAngle = 0;
+}
+
+Steering::~Steering()
+{
+    
+}
+
+void Steering::setSteerAngle(int angle)
+{
+    if (angle > MAX_STEER_ANGLE) angle = MAX_STEER_ANGLE;
+    if (angle < MIN_STEER_ANGLE) angle = MIN_STEER_ANGLE;
+    _steerAngle = angle;
+}
+
+void Steering::addToSteerAngle(int angle)
+{
+    int sum = _steerAngle + angle;
+    setSteerAngle(sum);
+}
+
+int Steering::getSteerAngle()
+{
+    return _steerAngle;
+}
+
+int Steering::readCurrentAngle()
+{
+    _currentAngle = 5; //replace by reading the sensor
+    return _currentAngle;
+}
+
+int Steering::getCurrentAngle()
+{
+    return _currentAngle;
+}
+
+void Steering::turn(float percentage)
+{    
+    //write to motor -1 ,1 direction
+    _pwm.write(abs(percentage)/100.0);
+    if (percentage < 0) _dir.write(0);
+    else _dir.write(1);
+}
\ No newline at end of file
diff -r 21d9efc7ecb6 -r 787f4284d968 Steering.h
--- a/Steering.h	Mon Jun 12 19:58:12 2017 +0000
+++ b/Steering.h	Thu Jul 13 13:42:23 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+
+#ifndef STEERING_H
+#define STEERING_H
+
+#define PIN_PWM_STEERING p26 //or whatever
+#define PIN_DIR_STEERING p15 //or whatever
+
+#define MAX_PWM_SIGNAL 0.9f
+
+#define MAX_STEER_ANGLE 80
+#define MIN_STEER_ANGLE -80
+
+class Steering
+{
+    public:
+    
+    Steering();
+    ~Steering();
+    
+    void turn(float percentage);
+    void setSteerAngle(int angle);
+    void addToSteerAngle(int angle);
+    int getSteerAngle();
+    int readCurrentAngle();
+    int getCurrentAngle();
+    
+    private:
+    
+    int _steerAngle;
+    int _currentAngle;
+    
+    PwmOut _pwm;
+    DigitalOut _dir;
+    
+};
+
+#endif
\ No newline at end of file
diff -r 21d9efc7ecb6 -r 787f4284d968 Sterring.cpp