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.
Dependents: BMT-K9_encoder BMT-K9-Regelaar K9motoraansturing_copy EMGverwerking ... more
encoder.h
00001 #ifndef _ENCODER_H_ 00002 #define _ENCODER_H_ 00003 00004 #include "mbed.h" 00005 00006 /** Encoder class. 00007 * Used to read out incremental position encoder. Decodes position in X2 configuration. 00008 * 00009 * Speed estimation is very crude and computationally intensive. Turned off by default 00010 * 00011 * Example: 00012 * @code 00013 * #include "mbed.h" 00014 * #include "Encoder.h" 00015 * 00016 * Encoder motor1(PTD0,PTC9,true); 00017 * Serial pc(USBTX,USBRX); 00018 * pc.baud(115200); 00019 * while(1) { 00020 * wait(0.2); 00021 * pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed()); 00022 * } 00023 * @endcode 00024 */ 00025 class Encoder 00026 { 00027 public: 00028 /** Create Encoder instance 00029 @param int_a Pin to be used as InterruptIn! Be careful, as not all pins on all platforms may be used as InterruptIn. 00030 @param int_b second encoder pin, used as DigitalIn. Can be any DigitalIn pin, not necessarily on InterruptIn location 00031 @param speed boolean value to determine whether speed calculation is done in interrupt routine. Default false (no speed calculation) 00032 */ 00033 00034 Encoder(PinName int_a, PinName int_b, bool speed=false); 00035 /** Request position 00036 @returns current position in encoder counts 00037 */ 00038 int32_t getPosition(){return m_position;} 00039 /** Overwrite position 00040 @param pos position to be written 00041 */ 00042 void setPosition(int32_t pos){m_position = pos;} 00043 /** Request speed 00044 @returns current speed 00045 */ 00046 float getSpeed(){return m_speed;} 00047 private: 00048 void encoderFalling(void); 00049 void encoderRising(void); 00050 bool m_speed_enabled; 00051 Timer EncoderTimer; 00052 Timeout EncoderTimeout; 00053 InterruptIn pin_a; 00054 DigitalIn pin_b; 00055 int32_t m_position; 00056 float m_speed; 00057 void timeouthandler(void); 00058 bool zero_speed; 00059 }; 00060 00061 00062 #endif //_ENCODER_H_
Generated on Fri Jul 15 2022 01:13:58 by
