![](/media/cache/profiles/e464656edca5e58850f8cec98cbb979b.50x50_q85.png)
encoder read old ways
Dependencies: mbed QEI_hw SDFileSystem_Sherckuith FATFileSystem rtos
main.cpp@1:4e2dc947ca3c, 2019-08-01 (annotated)
- Committer:
- eembed
- Date:
- Thu Aug 01 07:57:48 2019 +0000
- Revision:
- 1:4e2dc947ca3c
- Parent:
- 0:d3d96129e821
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eembed | 0:d3d96129e821 | 1 | #include "mbed.h" |
eembed | 0:d3d96129e821 | 2 | #include "qeihw.h" |
eembed | 0:d3d96129e821 | 3 | |
eembed | 0:d3d96129e821 | 4 | QEIHW qei_m(QEI_DIRINV_NONE, QEI_SIGNALMODE_QUAD, QEI_CAPMODE_2X, QEI_INVINX_NONE ); |
eembed | 0:d3d96129e821 | 5 | int dt_us=150; |
eembed | 0:d3d96129e821 | 6 | float send_m_angle = 0.0; |
eembed | 0:d3d96129e821 | 7 | float inc = 0; |
eembed | 0:d3d96129e821 | 8 | int32_t temp, position = 0; |
eembed | 0:d3d96129e821 | 9 | |
eembed | 0:d3d96129e821 | 10 | DigitalIn safety_14(p14); |
eembed | 0:d3d96129e821 | 11 | DigitalIn safety_15(p13); |
eembed | 0:d3d96129e821 | 12 | DigitalOut myled(LED1); |
eembed | 0:d3d96129e821 | 13 | DigitalOut myled3(LED3); |
eembed | 0:d3d96129e821 | 14 | DigitalIn safety_5(p5); |
eembed | 0:d3d96129e821 | 15 | DigitalIn safety_6(p6); |
eembed | 0:d3d96129e821 | 16 | DigitalIn safety_7(p7); |
eembed | 0:d3d96129e821 | 17 | DigitalIn safety_8(p8); |
eembed | 0:d3d96129e821 | 18 | DigitalIn safety_9(p9); |
eembed | 0:d3d96129e821 | 19 | DigitalIn safety_10(p10); |
eembed | 0:d3d96129e821 | 20 | DigitalIn safety_11(p15); |
eembed | 0:d3d96129e821 | 21 | DigitalIn safety_12(p12); |
eembed | 0:d3d96129e821 | 22 | DigitalIn safety_13(p11); |
eembed | 0:d3d96129e821 | 23 | DigitalIn safety_16(p16); |
eembed | 0:d3d96129e821 | 24 | DigitalIn safety_17(p17); |
eembed | 0:d3d96129e821 | 25 | DigitalIn safety_18(p18); |
eembed | 0:d3d96129e821 | 26 | DigitalIn safety_19(p19); |
eembed | 0:d3d96129e821 | 27 | DigitalIn safety_20(p20); |
eembed | 0:d3d96129e821 | 28 | DigitalIn safety_21(p21); |
eembed | 0:d3d96129e821 | 29 | DigitalIn safety_22(p22); |
eembed | 0:d3d96129e821 | 30 | DigitalIn safety_23(p23); |
eembed | 0:d3d96129e821 | 31 | DigitalIn safety_24(p24); |
eembed | 0:d3d96129e821 | 32 | DigitalIn safety_25(p25); |
eembed | 0:d3d96129e821 | 33 | DigitalIn safety_26(p26); |
eembed | 0:d3d96129e821 | 34 | DigitalIn safety_27(p27); |
eembed | 0:d3d96129e821 | 35 | DigitalIn safety_28(p28); |
eembed | 0:d3d96129e821 | 36 | DigitalIn safety_29(p29); |
eembed | 0:d3d96129e821 | 37 | DigitalIn safety_30(p30); |
eembed | 0:d3d96129e821 | 38 | |
eembed | 0:d3d96129e821 | 39 | Ethernet eth; |
eembed | 0:d3d96129e821 | 40 | Ticker ticker; |
eembed | 0:d3d96129e821 | 41 | |
eembed | 0:d3d96129e821 | 42 | // Encoder Constants |
eembed | 0:d3d96129e821 | 43 | float const encoder_pulses_m = 10000.0; |
eembed | 0:d3d96129e821 | 44 | #define PI 3.141592653 |
eembed | 0:d3d96129e821 | 45 | |
eembed | 0:d3d96129e821 | 46 | |
eembed | 0:d3d96129e821 | 47 | void send(void) |
eembed | 0:d3d96129e821 | 48 | { |
eembed | 0:d3d96129e821 | 49 | inc++; |
eembed | 0:d3d96129e821 | 50 | position = qei_m.GetPosition(); |
eembed | 0:d3d96129e821 | 51 | send_m_angle = position * 2.0 * PI / encoder_pulses_m; |
eembed | 0:d3d96129e821 | 52 | eth.write((char *)&send_m_angle, sizeof(send_m_angle)); |
eembed | 0:d3d96129e821 | 53 | //eth.write((char *)&inc, sizeof(inc)); |
eembed | 0:d3d96129e821 | 54 | myled3 = !myled3; |
eembed | 0:d3d96129e821 | 55 | eth.send(); |
eembed | 0:d3d96129e821 | 56 | // wait_us(10); |
eembed | 0:d3d96129e821 | 57 | // return 0; |
eembed | 0:d3d96129e821 | 58 | } |
eembed | 0:d3d96129e821 | 59 | |
eembed | 0:d3d96129e821 | 60 | int main() |
eembed | 0:d3d96129e821 | 61 | { |
eembed | 0:d3d96129e821 | 62 | eth.set_link(Ethernet::HalfDuplex100); |
eembed | 0:d3d96129e821 | 63 | wait_ms(1000); // Needed after startup. |
eembed | 0:d3d96129e821 | 64 | |
eembed | 0:d3d96129e821 | 65 | if(eth.link()) |
eembed | 0:d3d96129e821 | 66 | { |
eembed | 0:d3d96129e821 | 67 | myled = 1; |
eembed | 0:d3d96129e821 | 68 | } else |
eembed | 0:d3d96129e821 | 69 | { |
eembed | 0:d3d96129e821 | 70 | myled = 0; |
eembed | 0:d3d96129e821 | 71 | } |
eembed | 0:d3d96129e821 | 72 | |
eembed | 0:d3d96129e821 | 73 | int32_t temp, position = 0; |
eembed | 0:d3d96129e821 | 74 | qei_m.SetDigiFilter(480UL); |
eembed | 0:d3d96129e821 | 75 | qei_m.SetMaxPosition(0xFFFFFFFF); |
eembed | 0:d3d96129e821 | 76 | |
eembed | 0:d3d96129e821 | 77 | ticker.attach_us(&send, dt_us); |
eembed | 0:d3d96129e821 | 78 | //ticker.attach_us(&Control_body, dt_us); |
eembed | 0:d3d96129e821 | 79 | /* while(1) { |
eembed | 0:d3d96129e821 | 80 | inc++; |
eembed | 0:d3d96129e821 | 81 | position = qei_m.GetPosition(); |
eembed | 0:d3d96129e821 | 82 | send_m_angle = position * 2.0 * PI / encoder_pulses_m; |
eembed | 0:d3d96129e821 | 83 | eth.write((char *)&send_m_angle, sizeof(send_m_angle)); |
eembed | 0:d3d96129e821 | 84 | //eth.write((char *)&inc, sizeof(inc)); |
eembed | 0:d3d96129e821 | 85 | myled3 = !myled3; |
eembed | 0:d3d96129e821 | 86 | eth.send(); |
eembed | 0:d3d96129e821 | 87 | wait_us(10); |
eembed | 0:d3d96129e821 | 88 | } */ |
eembed | 0:d3d96129e821 | 89 | } |