Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PID mbed-rtos
Phaserunner.h
00001 /** 00002 * Handelt die Kommunikation (Lesen und Schreiben) mit den Phaserunnern 00003 */ 00004 00005 #ifndef PHASERUNNER_H 00006 #define PHASERUNNER_H 00007 00008 #include "mbed.h" 00009 #include "rtos.h" 00010 00011 class Phaserunner { 00012 private: 00013 //Private constants 00014 static const uint8_t BUFLEN = 255; 00015 00016 //Adressen 00017 static const unsigned short REMOTE_THROTTLE_VOLTAGE = 495; 00018 static const unsigned short REMOTE_ANALOG_BREAK_VOLTAGE = 497; 00019 static const unsigned short MOTOR_CURRENT = 262; 00020 static const unsigned short LAST_FAULT = 269; 00021 static const unsigned short EBRAKESOURCE = 249; 00022 00023 //Modbus-Protokoll 00024 static const uint8_t SCHREIBANTWORT = 0x10; 00025 static const uint8_t LESEANTWORT = 0x03; 00026 00027 //Pedale oder Motor 00028 const uint8_t PHASERUNNERTYPE; 00029 00030 //Sonstiges 00031 static const uint16_t WRITE_PERIOD = 3; //Minimaler Zeitintervall zwischen zwei Messages an den Phaserunner [ms] 00032 static const float TICKER_PERIOD = 0.02f; //Zeitintervall für das Schreiben auf den Phaserunner [s] 00033 00034 AnalogOut* analogOut; //Wenn der Phaserunner Pedale kontrolliert, hat er einen analogOut 00035 00036 //Thread thread; //Wird für die Funktion writeToPhaserunner() gebraucht 00037 00038 Ticker ticker; //Wird gebraucht um nicht zu häufig zu schreiben 00039 uint8_t timer; //Zeit, die vergehen muss, bis wieder geschrieben werden kann [ms] 00040 00041 //Verbindung zum Phaserunner 00042 RawSerial& connection; 00043 00044 //Buffer in das gelesen wird. 00045 uint8_t writeBuffer[BUFLEN]; 00046 00047 //Buffer aus dem geschrieben wird. 00048 uint8_t read_buffer[BUFLEN]; 00049 00050 //State valiables 00051 float frequency; 00052 float voltage; 00053 float current; 00054 uint16_t error; 00055 uint16_t newTorque; 00056 uint16_t newRecuperation; 00057 00058 /** 00059 * Wartet auf ein Byte. Wenn ein Datenstring gelesen wird, werden die Daten mithilfe einer Zustandsmaschine abgespeichert. 00060 */ 00061 void Rx_interrupt(); 00062 00063 /** 00064 * @brief Bereitet buf darauf vor, versendet zu werden. 00065 * @param buf: Byte-Array 00066 * @param addr: Adresse des Registers, das beschrieben wird 00067 * @param value: Wert der in das Register geschrieben wird 00068 */ 00069 static int WriteRegister(uint8_t* buf, unsigned short addr, unsigned short value); 00070 00071 /** 00072 * @brief Sendet einen Schreibbefehl auf einen Phaserunner 00073 * @param writeBuf: Byte-Array in das geschrieben wird. 00074 * @param registerAddress: Adresse des Registers aus dem gelesen wird. 00075 */ 00076 static int readRegister(uint8_t *buf, uint16_t registerAddress); 00077 00078 /** 00079 * @brief Sendet ein Byte-Array zum Phaserunner 00080 * @param adress: Adresse des Zielregisters 00081 * @param value: Wert der in das Register geschriebern werden soll. 00082 * @return Anzahl gesendeter Bytes 00083 */ 00084 int sendBuffer(unsigned short adress, unsigned short value); 00085 00086 /** 00087 * @brief Sendet den writeBuffer 00088 * @param: Länge des zu sendenden Arrays 00089 * @return: Anzahl gesendeter Bytes 00090 */ 00091 int sendBuffer(int length); 00092 00093 /** 00094 * @brief: Liest ein Register aus. 00095 * @param adress: Adresse des Registers aus dem gelesen werden soll. 00096 * @return: Anzahl gelesener Bytes 00097 */ 00098 int readBuffer(uint16_t adress); 00099 00100 /** 00101 * @brief: Schreibt ein Drehmoment auf den Phaserunner. 00102 * @param: torque Drehmoment in percent 00103 */ 00104 void writeTorque(uint8_t torque); 00105 00106 /** 00107 * @brief Schreibt einen Analogwert mit dem das Drehmoment kontrolliert wird. 00108 * @param torque 00109 */ 00110 void analogTorque(uint8_t torque); 00111 00112 /** 00113 * @brief: Schreibt den Rekuperationswert auf den Phaserunner. 00114 * @param: recuperation Rekupertation in Prozent 00115 */ 00116 void writeRecuperation(uint8_t recuperation); 00117 00118 /** 00119 * @brief: Prüfziffer berechnen 00120 * @param: msgByte Byte-Array 00121 * @param: length length of Byte-Array 00122 */ 00123 static uint16_t getCRC(uint8_t* msgByte, uint8_t length); 00124 00125 /** 00126 * @brief: Sendet Befehle dem Phaserunner sobald es möglich ist. 00127 */ 00128 //void writeToPhaserunner(); 00129 00130 /** 00131 * @brief: Sendet einen Schreibbefehl für die Drehgewschwindigkeit, die Stromstärke und die Spannung 00132 */ 00133 void readRPM(); 00134 00135 /** 00136 * @brief: Liest das Fehlerregister aus 00137 * @return Byte 00138 */ 00139 uint16_t readFaults(); 00140 00141 /** 00142 * Reduziert den timer (Wird mit dem Ticker aufgerufen). 00143 */ 00144 void reduce_timer(); 00145 00146 public: 00147 static const uint8_t MAX_TORQUE_GAIN = 2; //Maximaler Sprung für Drehmoment 00148 static const uint8_t MIN_RECUPERATION = 10; //Schwellwert für die Aktivierung des Daumengriffbetätigers 00149 static const uint8_t MIN_HANDGRIFF = 5; //Schwellwert für die Aktivierung des Handgriffbetätigers 00150 00151 static const uint8_t PEDALS = 0; //Phaserunner Type Pedal 00152 static const uint8_t MOTORS = 1; //Phaserunner Type Motor 00153 00154 //int sendBuffer(unsigned short adress, unsigned short value); 00155 //int readBuffer(uint16_t adress); 00156 /** 00157 * @brief Initialisiert ein Phaserunner-Objekt 00158 * @param connection: Serielle Schnittstelle zum Phaserunner 00159 */ 00160 Phaserunner(RawSerial& connection); 00161 00162 /** 00163 * Konstruktor für Pedale 00164 * @param connection 00165 * @param analogOut 00166 */ 00167 Phaserunner(RawSerial& connection, AnalogOut* analogOut); 00168 00169 /** 00170 * @brief: Schreibt ein Drehmoment ins Phaserunnerobjekt, das dann geschrieben wird. 00171 * @param: torque Drehmoment in Prozent 00172 */ 00173 void setTorque(uint8_t torque); 00174 00175 /** 00176 * @brief: Schreibt einen Rekuperationswert ins Phaserunnerobjekt, dass dann geschrieben wird. 00177 * @param: recuperation Rekuperationswert in Prozent 00178 */ 00179 void setRecuperation(uint8_t recuperation); 00180 00181 /** 00182 * @return frequenz 00183 */ 00184 float getFrequency(); 00185 00186 /** 00187 * @return strom 00188 */ 00189 float getCurrent(); 00190 00191 /** 00192 * @return spannung 00193 */ 00194 float getVoltage(); 00195 00196 /** 00197 * @return Ebrike Source 00198 */ 00199 int getRegister(int address); 00200 00201 //Delete 00202 uint8_t badBuf[256]; 00203 uint8_t bufPointer; 00204 uint8_t read; 00205 DigitalOut led; 00206 00207 uint16_t getRecup(); 00208 }; 00209 00210 #endif
Generated on Mon Aug 1 2022 09:49:43 by
