ti bisogna il phaserunner

Dependencies:   mbed PID mbed-rtos

Committer:
beacon
Date:
Tue Jun 04 19:03:39 2019 +0000
Revision:
11:39bd79605827
Parent:
9:56aed8c6779f
ti bisogna il phaserunner

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EpicG10 0:8a660654d511 1 /**
EpicG10 0:8a660654d511 2 * Handelt die Kommunikation (Lesen und Schreiben) mit den Phaserunnern
EpicG10 0:8a660654d511 3 */
EpicG10 0:8a660654d511 4
EpicG10 0:8a660654d511 5 #ifndef PHASERUNNER_H
EpicG10 0:8a660654d511 6 #define PHASERUNNER_H
EpicG10 0:8a660654d511 7
EpicG10 0:8a660654d511 8 #include "mbed.h"
EpicG10 0:8a660654d511 9 #include "rtos.h"
EpicG10 0:8a660654d511 10
EpicG10 0:8a660654d511 11 class Phaserunner {
EpicG10 0:8a660654d511 12 private:
EpicG10 0:8a660654d511 13 //Private constants
EpicG10 0:8a660654d511 14 static const uint8_t BUFLEN = 255;
EpicG10 0:8a660654d511 15
EpicG10 0:8a660654d511 16 //Adressen
EpicG10 0:8a660654d511 17 static const unsigned short REMOTE_THROTTLE_VOLTAGE = 495;
EpicG10 0:8a660654d511 18 static const unsigned short REMOTE_ANALOG_BREAK_VOLTAGE = 497;
EpicG10 0:8a660654d511 19 static const unsigned short MOTOR_CURRENT = 262;
EpicG10 0:8a660654d511 20 static const unsigned short LAST_FAULT = 269;
EpicG10 6:a80300ee574d 21 static const unsigned short EBRAKESOURCE = 249;
EpicG10 0:8a660654d511 22
EpicG10 0:8a660654d511 23 //Modbus-Protokoll
EpicG10 0:8a660654d511 24 static const uint8_t SCHREIBANTWORT = 0x10;
EpicG10 0:8a660654d511 25 static const uint8_t LESEANTWORT = 0x03;
beacon 11:39bd79605827 26
beacon 11:39bd79605827 27 //Pedale oder Motor
beacon 11:39bd79605827 28 const uint8_t PHASERUNNERTYPE;
EpicG10 0:8a660654d511 29
EpicG10 0:8a660654d511 30 //Sonstiges
EpicG10 0:8a660654d511 31 static const uint16_t WRITE_PERIOD = 3; //Minimaler Zeitintervall zwischen zwei Messages an den Phaserunner [ms]
EpicG10 0:8a660654d511 32 static const float TICKER_PERIOD = 0.02f; //Zeitintervall für das Schreiben auf den Phaserunner [s]
beacon 11:39bd79605827 33
beacon 11:39bd79605827 34 AnalogOut* analogOut; //Wenn der Phaserunner Pedale kontrolliert, hat er einen analogOut
beacon 11:39bd79605827 35
EpicG10 0:8a660654d511 36 //Thread thread; //Wird für die Funktion writeToPhaserunner() gebraucht
beacon 11:39bd79605827 37
beacon 11:39bd79605827 38 Ticker ticker; //Wird gebraucht um nicht zu häufig zu schreiben
beacon 11:39bd79605827 39 uint8_t timer; //Zeit, die vergehen muss, bis wieder geschrieben werden kann [ms]
EpicG10 0:8a660654d511 40
EpicG10 0:8a660654d511 41 //Verbindung zum Phaserunner
EpicG10 0:8a660654d511 42 RawSerial& connection;
EpicG10 0:8a660654d511 43
EpicG10 0:8a660654d511 44 //Buffer in das gelesen wird.
EpicG10 0:8a660654d511 45 uint8_t writeBuffer[BUFLEN];
EpicG10 0:8a660654d511 46
EpicG10 0:8a660654d511 47 //Buffer aus dem geschrieben wird.
EpicG10 0:8a660654d511 48 uint8_t read_buffer[BUFLEN];
EpicG10 0:8a660654d511 49
EpicG10 0:8a660654d511 50 //State valiables
EpicG10 0:8a660654d511 51 float frequency;
EpicG10 0:8a660654d511 52 float voltage;
EpicG10 0:8a660654d511 53 float current;
EpicG10 0:8a660654d511 54 uint16_t error;
EpicG10 0:8a660654d511 55 uint16_t newTorque;
EpicG10 0:8a660654d511 56 uint16_t newRecuperation;
EpicG10 0:8a660654d511 57
EpicG10 0:8a660654d511 58 /**
EpicG10 0:8a660654d511 59 * Wartet auf ein Byte. Wenn ein Datenstring gelesen wird, werden die Daten mithilfe einer Zustandsmaschine abgespeichert.
EpicG10 0:8a660654d511 60 */
EpicG10 0:8a660654d511 61 void Rx_interrupt();
EpicG10 0:8a660654d511 62
EpicG10 0:8a660654d511 63 /**
EpicG10 0:8a660654d511 64 * @brief Bereitet buf darauf vor, versendet zu werden.
EpicG10 0:8a660654d511 65 * @param buf: Byte-Array
EpicG10 0:8a660654d511 66 * @param addr: Adresse des Registers, das beschrieben wird
EpicG10 0:8a660654d511 67 * @param value: Wert der in das Register geschrieben wird
EpicG10 0:8a660654d511 68 */
EpicG10 0:8a660654d511 69 static int WriteRegister(uint8_t* buf, unsigned short addr, unsigned short value);
EpicG10 0:8a660654d511 70
EpicG10 0:8a660654d511 71 /**
EpicG10 0:8a660654d511 72 * @brief Sendet einen Schreibbefehl auf einen Phaserunner
EpicG10 0:8a660654d511 73 * @param writeBuf: Byte-Array in das geschrieben wird.
EpicG10 0:8a660654d511 74 * @param registerAddress: Adresse des Registers aus dem gelesen wird.
EpicG10 0:8a660654d511 75 */
EpicG10 0:8a660654d511 76 static int readRegister(uint8_t *buf, uint16_t registerAddress);
EpicG10 0:8a660654d511 77
EpicG10 0:8a660654d511 78 /**
EpicG10 0:8a660654d511 79 * @brief Sendet ein Byte-Array zum Phaserunner
EpicG10 0:8a660654d511 80 * @param adress: Adresse des Zielregisters
EpicG10 0:8a660654d511 81 * @param value: Wert der in das Register geschriebern werden soll.
EpicG10 0:8a660654d511 82 * @return Anzahl gesendeter Bytes
EpicG10 0:8a660654d511 83 */
beacon 11:39bd79605827 84 int sendBuffer(unsigned short adress, unsigned short value);
EpicG10 0:8a660654d511 85
EpicG10 0:8a660654d511 86 /**
EpicG10 0:8a660654d511 87 * @brief Sendet den writeBuffer
EpicG10 0:8a660654d511 88 * @param: Länge des zu sendenden Arrays
EpicG10 0:8a660654d511 89 * @return: Anzahl gesendeter Bytes
EpicG10 0:8a660654d511 90 */
EpicG10 0:8a660654d511 91 int sendBuffer(int length);
EpicG10 0:8a660654d511 92
EpicG10 0:8a660654d511 93 /**
EpicG10 0:8a660654d511 94 * @brief: Liest ein Register aus.
EpicG10 0:8a660654d511 95 * @param adress: Adresse des Registers aus dem gelesen werden soll.
EpicG10 0:8a660654d511 96 * @return: Anzahl gelesener Bytes
EpicG10 0:8a660654d511 97 */
beacon 11:39bd79605827 98 int readBuffer(uint16_t adress);
EpicG10 0:8a660654d511 99
EpicG10 0:8a660654d511 100 /**
EpicG10 0:8a660654d511 101 * @brief: Schreibt ein Drehmoment auf den Phaserunner.
EpicG10 0:8a660654d511 102 * @param: torque Drehmoment in percent
EpicG10 0:8a660654d511 103 */
EpicG10 0:8a660654d511 104 void writeTorque(uint8_t torque);
EpicG10 0:8a660654d511 105
EpicG10 0:8a660654d511 106 /**
beacon 11:39bd79605827 107 * @brief Schreibt einen Analogwert mit dem das Drehmoment kontrolliert wird.
beacon 11:39bd79605827 108 * @param torque
beacon 11:39bd79605827 109 */
beacon 11:39bd79605827 110 void analogTorque(uint8_t torque);
beacon 11:39bd79605827 111
beacon 11:39bd79605827 112 /**
EpicG10 0:8a660654d511 113 * @brief: Schreibt den Rekuperationswert auf den Phaserunner.
EpicG10 0:8a660654d511 114 * @param: recuperation Rekupertation in Prozent
EpicG10 0:8a660654d511 115 */
EpicG10 0:8a660654d511 116 void writeRecuperation(uint8_t recuperation);
EpicG10 0:8a660654d511 117
EpicG10 0:8a660654d511 118 /**
EpicG10 0:8a660654d511 119 * @brief: Prüfziffer berechnen
EpicG10 0:8a660654d511 120 * @param: msgByte Byte-Array
EpicG10 0:8a660654d511 121 * @param: length length of Byte-Array
EpicG10 0:8a660654d511 122 */
EpicG10 0:8a660654d511 123 static uint16_t getCRC(uint8_t* msgByte, uint8_t length);
EpicG10 0:8a660654d511 124
EpicG10 0:8a660654d511 125 /**
beacon 11:39bd79605827 126 * @brief: Sendet Befehle dem Phaserunner sobald es möglich ist.
EpicG10 0:8a660654d511 127 */
beacon 11:39bd79605827 128 //void writeToPhaserunner();
EpicG10 0:8a660654d511 129
EpicG10 0:8a660654d511 130 /**
EpicG10 0:8a660654d511 131 * @brief: Sendet einen Schreibbefehl für die Drehgewschwindigkeit, die Stromstärke und die Spannung
EpicG10 0:8a660654d511 132 */
EpicG10 0:8a660654d511 133 void readRPM();
EpicG10 0:8a660654d511 134
EpicG10 0:8a660654d511 135 /**
EpicG10 0:8a660654d511 136 * @brief: Liest das Fehlerregister aus
EpicG10 0:8a660654d511 137 * @return Byte
EpicG10 0:8a660654d511 138 */
EpicG10 0:8a660654d511 139 uint16_t readFaults();
EpicG10 0:8a660654d511 140
beacon 11:39bd79605827 141 /**
beacon 11:39bd79605827 142 * Reduziert den timer (Wird mit dem Ticker aufgerufen).
beacon 11:39bd79605827 143 */
beacon 11:39bd79605827 144 void reduce_timer();
beacon 11:39bd79605827 145
EpicG10 0:8a660654d511 146 public:
EpicG10 0:8a660654d511 147 static const uint8_t MAX_TORQUE_GAIN = 2; //Maximaler Sprung für Drehmoment
EpicG10 0:8a660654d511 148 static const uint8_t MIN_RECUPERATION = 10; //Schwellwert für die Aktivierung des Daumengriffbetätigers
EpicG10 0:8a660654d511 149 static const uint8_t MIN_HANDGRIFF = 5; //Schwellwert für die Aktivierung des Handgriffbetätigers
beacon 11:39bd79605827 150
beacon 11:39bd79605827 151 static const uint8_t PEDALS = 0; //Phaserunner Type Pedal
beacon 11:39bd79605827 152 static const uint8_t MOTORS = 1; //Phaserunner Type Motor
beacon 11:39bd79605827 153
beacon 11:39bd79605827 154 //int sendBuffer(unsigned short adress, unsigned short value);
beacon 11:39bd79605827 155 //int readBuffer(uint16_t adress);
EpicG10 0:8a660654d511 156 /**
EpicG10 0:8a660654d511 157 * @brief Initialisiert ein Phaserunner-Objekt
EpicG10 0:8a660654d511 158 * @param connection: Serielle Schnittstelle zum Phaserunner
EpicG10 0:8a660654d511 159 */
EpicG10 0:8a660654d511 160 Phaserunner(RawSerial& connection);
EpicG10 0:8a660654d511 161
EpicG10 0:8a660654d511 162 /**
beacon 11:39bd79605827 163 * Konstruktor für Pedale
beacon 11:39bd79605827 164 * @param connection
beacon 11:39bd79605827 165 * @param analogOut
beacon 11:39bd79605827 166 */
beacon 11:39bd79605827 167 Phaserunner(RawSerial& connection, AnalogOut* analogOut);
beacon 11:39bd79605827 168
beacon 11:39bd79605827 169 /**
EpicG10 0:8a660654d511 170 * @brief: Schreibt ein Drehmoment ins Phaserunnerobjekt, das dann geschrieben wird.
EpicG10 0:8a660654d511 171 * @param: torque Drehmoment in Prozent
EpicG10 0:8a660654d511 172 */
EpicG10 0:8a660654d511 173 void setTorque(uint8_t torque);
EpicG10 0:8a660654d511 174
EpicG10 0:8a660654d511 175 /**
EpicG10 0:8a660654d511 176 * @brief: Schreibt einen Rekuperationswert ins Phaserunnerobjekt, dass dann geschrieben wird.
EpicG10 0:8a660654d511 177 * @param: recuperation Rekuperationswert in Prozent
EpicG10 0:8a660654d511 178 */
EpicG10 0:8a660654d511 179 void setRecuperation(uint8_t recuperation);
EpicG10 0:8a660654d511 180
EpicG10 0:8a660654d511 181 /**
EpicG10 0:8a660654d511 182 * @return frequenz
EpicG10 0:8a660654d511 183 */
EpicG10 0:8a660654d511 184 float getFrequency();
EpicG10 0:8a660654d511 185
EpicG10 0:8a660654d511 186 /**
EpicG10 6:a80300ee574d 187 * @return strom
EpicG10 0:8a660654d511 188 */
EpicG10 0:8a660654d511 189 float getCurrent();
EpicG10 0:8a660654d511 190
EpicG10 0:8a660654d511 191 /**
EpicG10 0:8a660654d511 192 * @return spannung
EpicG10 0:8a660654d511 193 */
EpicG10 0:8a660654d511 194 float getVoltage();
beacon 11:39bd79605827 195
EpicG10 6:a80300ee574d 196 /**
EpicG10 6:a80300ee574d 197 * @return Ebrike Source
EpicG10 6:a80300ee574d 198 */
EpicG10 6:a80300ee574d 199 int getRegister(int address);
EpicG10 0:8a660654d511 200
EpicG10 0:8a660654d511 201 //Delete
EpicG10 0:8a660654d511 202 uint8_t badBuf[256];
EpicG10 0:8a660654d511 203 uint8_t bufPointer;
EpicG10 0:8a660654d511 204 uint8_t read;
EpicG10 0:8a660654d511 205 DigitalOut led;
beacon 11:39bd79605827 206
EpicG10 0:8a660654d511 207 uint16_t getRecup();
EpicG10 0:8a660654d511 208 };
EpicG10 0:8a660654d511 209
EpicG10 0:8a660654d511 210 #endif