FSM met EMG kalibratie

Committer:
MatthewMaat
Date:
Fri Sep 20 09:47:17 2019 +0000
Revision:
1:5b89addde1f0
pwm test 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MatthewMaat 1:5b89addde1f0 1 #ifndef _ENCODER_H_
MatthewMaat 1:5b89addde1f0 2 #define _ENCODER_H_
MatthewMaat 1:5b89addde1f0 3
MatthewMaat 1:5b89addde1f0 4 #include "mbed.h"
MatthewMaat 1:5b89addde1f0 5
MatthewMaat 1:5b89addde1f0 6 /** Encoder class.
MatthewMaat 1:5b89addde1f0 7 * Used to read out incremental position encoder. Decodes position in X2 configuration.
MatthewMaat 1:5b89addde1f0 8 *
MatthewMaat 1:5b89addde1f0 9 * Speed estimation is very crude and computationally intensive. Turned off by default
MatthewMaat 1:5b89addde1f0 10 *
MatthewMaat 1:5b89addde1f0 11 * Example:
MatthewMaat 1:5b89addde1f0 12 * @code
MatthewMaat 1:5b89addde1f0 13 * #include "mbed.h"
MatthewMaat 1:5b89addde1f0 14 * #include "Encoder.h"
MatthewMaat 1:5b89addde1f0 15 *
MatthewMaat 1:5b89addde1f0 16 * Encoder motor1(PTD0,PTC9,true);
MatthewMaat 1:5b89addde1f0 17 * Serial pc(USBTX,USBRX);
MatthewMaat 1:5b89addde1f0 18 * pc.baud(115200);
MatthewMaat 1:5b89addde1f0 19 * while(1) {
MatthewMaat 1:5b89addde1f0 20 * wait(0.2);
MatthewMaat 1:5b89addde1f0 21 * pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed());
MatthewMaat 1:5b89addde1f0 22 * }
MatthewMaat 1:5b89addde1f0 23 * @endcode
MatthewMaat 1:5b89addde1f0 24 */
MatthewMaat 1:5b89addde1f0 25 class Encoder
MatthewMaat 1:5b89addde1f0 26 {
MatthewMaat 1:5b89addde1f0 27 public:
MatthewMaat 1:5b89addde1f0 28 /** Create Encoder instance
MatthewMaat 1:5b89addde1f0 29 @param int_a Pin to be used as InterruptIn! Be careful, as not all pins on all platforms may be used as InterruptIn.
MatthewMaat 1:5b89addde1f0 30 @param int_b second encoder pin, used as DigitalIn. Can be any DigitalIn pin, not necessarily on InterruptIn location
MatthewMaat 1:5b89addde1f0 31 @param speed boolean value to determine whether speed calculation is done in interrupt routine. Default false (no speed calculation)
MatthewMaat 1:5b89addde1f0 32 */
MatthewMaat 1:5b89addde1f0 33
MatthewMaat 1:5b89addde1f0 34 Encoder(PinName int_a, PinName int_b, bool speed=false);
MatthewMaat 1:5b89addde1f0 35 /** Request position
MatthewMaat 1:5b89addde1f0 36 @returns current position in encoder counts
MatthewMaat 1:5b89addde1f0 37 */
MatthewMaat 1:5b89addde1f0 38 int32_t getPosition(){return m_position;}
MatthewMaat 1:5b89addde1f0 39 /** Overwrite position
MatthewMaat 1:5b89addde1f0 40 @param pos position to be written
MatthewMaat 1:5b89addde1f0 41 */
MatthewMaat 1:5b89addde1f0 42 void setPosition(int32_t pos){m_position = pos;}
MatthewMaat 1:5b89addde1f0 43 /** Request speed
MatthewMaat 1:5b89addde1f0 44 @returns current speed
MatthewMaat 1:5b89addde1f0 45 */
MatthewMaat 1:5b89addde1f0 46 float getSpeed(){return m_speed;}
MatthewMaat 1:5b89addde1f0 47 private:
MatthewMaat 1:5b89addde1f0 48 void encoderFalling(void);
MatthewMaat 1:5b89addde1f0 49 void encoderRising(void);
MatthewMaat 1:5b89addde1f0 50 bool m_speed_enabled;
MatthewMaat 1:5b89addde1f0 51 Timer EncoderTimer;
MatthewMaat 1:5b89addde1f0 52 Timeout EncoderTimeout;
MatthewMaat 1:5b89addde1f0 53 InterruptIn pin_a;
MatthewMaat 1:5b89addde1f0 54 DigitalIn pin_b;
MatthewMaat 1:5b89addde1f0 55 int32_t m_position;
MatthewMaat 1:5b89addde1f0 56 float m_speed;
MatthewMaat 1:5b89addde1f0 57 void timeouthandler(void);
MatthewMaat 1:5b89addde1f0 58 bool zero_speed;
MatthewMaat 1:5b89addde1f0 59 };
MatthewMaat 1:5b89addde1f0 60
MatthewMaat 1:5b89addde1f0 61
MatthewMaat 1:5b89addde1f0 62 #endif //_ENCODER_H_