IR control car "spinner" 赤外線コントロールラジコン"spinner"の本体&プロポ統合版プログラムです
Dependencies: Motor Propo_RemotoIR mbed
Revision 0:6825e25b7428, committed 2013-10-16
- Comitter:
- suupen
- Date:
- Wed Oct 16 02:45:27 2013 +0000
- Commit message:
- IR control car "spinner"
Changed in this revision
diff -r 000000000000 -r 6825e25b7428 Motor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r 6825e25b7428 Propo_RemotoIR.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Propo_RemotoIR.lib Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/suupen/code/Propo_RemotoIR/#ec76e93a4d7c
diff -r 000000000000 -r 6825e25b7428 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,15 @@ +#include "mbed.h" + + +#include "spinner.h" +#include "propo.h" + +int main() +{ + initialSpinner(); + initialPropo(); + while(1) { + mainSpinner(); + } +} +
diff -r 000000000000 -r 6825e25b7428 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file
diff -r 000000000000 -r 6825e25b7428 propo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/propo.cpp Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,87 @@ +/* ir propo + * microcomputer + * LPC1114FN28 + * used pin + * dp1 : irLED output + * dp9 : analog joystic x axis input + * dp10: analog joystic y axis input + * joystic + * akizuki(http://akizukidenshi.com/catalog/g/gP-04048/) + * analog joystic + * <schematic> + * Vcc(3.3[V]) : joystic pin1'(X axis) pin3(Y axis) + * GND(0[V]) : joystic pin3'(X axis) pin1(Y axis) + * LPC1114FN28 dp9 : joystic pin2'(X axis) + * LPC1114FN28 dp10: joystic pin2 (Y axis) + * <joystic fixed data> + * X axis -8 to 7 :int8_t + * Y axis -8 to 7 :int8_t + * + * ir send + * akizuki (http://akizukidenshi.com/catalog/g/gP-04048/) + * OSI5FU3A11C + * <schematic> + * setting If=50[mA] + * LPC1114FN28 dp1 : irLED(anode) + * GND(0[V]) : - 40[ohm] - irLED(cathod) + * <send format> + * SONY format + * send cycle : 100[ms] + * buf[0] :x axis + * buf[1] :y axis +*/ +#include "mbed.h" +#include "propo.h" +#include "TransmitterIR.h" + + +void interruptPropo(void); + +//#define DBG_PROPO + +#ifdef DBG_PROPO +DigitalOut myled(LED2); +Serial pc(dp16, dp15); +#endif // DBG_PROPO +//------------------------ +// joystic +AnalogIn Xin(dp9); +AnalogIn Yin(dp10); + +int8_t XinData; +int8_t YinData; +//------------------------- +// ir control +TransmitterIR ir_tx(dp1); +RemoteIR::Format format = RemoteIR::SONY; +uint8_t buf[2] = {0x00, 0x00}; +int bitcount = 16; + +Ticker timer; + +void initialPropo(void) +{ + timer.attach(&interruptPropo, 0.1); +} + +void interruptPropo() +{ + // analog 16bit unsigned data(uint16_t) to 4bit signed data(int8_t) + XinData = (int8_t)((int16_t)(Xin.read_u16() >> 12) - 0x8); + YinData = (int8_t)((int16_t)(Yin.read_u16() >> 12) - 0x8); + + buf[0] = XinData; + buf[1] = YinData; + + // send data + if(ir_tx.getState() == TransmitterIR::Idle) { + bitcount = ir_tx.setData(format, buf, bitcount); + } + +#ifdef DBG_PROPO + pc.printf("X = %02d, Y = %02d \r\n",XinData,YinData); + myled = !myled; +#endif // DBG_PROPO +} + +
diff -r 000000000000 -r 6825e25b7428 propo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/propo.h Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,6 @@ +#ifndef _PROPO_H_ +#define _PROPO_H_ + +void initialPropo(void); + +#endif // __PROPO_H_
diff -r 000000000000 -r 6825e25b7428 spinner.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spinner.cpp Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,137 @@ +/* spinner base pcb + * <use ir propo> + * LPC1114FN28 sony format propo + * + * <spinner circit> + * LPC1114FN28 + * dp28 : ir reciver + * dp18,dp17,dp25: (pwm fwd rev) Right motor control + * dp2,dp4,dp6:(pwm fwd rev) Left motor control + * + * dp11,dp13,dp14,dp26 (LED1,2,3,4):lookup the ir recive condition + +*/ + +#include "mbed.h" +#include "Motor.h" + +#include "ReceiverIR.h" + +#define DBG +//#define DBG2 // motor dousa kakunin + +#ifdef DBG +Serial pc(dp16, dp15); //tx,rx +#endif // DBG + +//----------------------- +// ir Library +ReceiverIR ir_rx(dp28); +RemoteIR::Format formatRx; +uint8_t bufRx[10]; // nomal no is "2". +int bitcountRx; + +DigitalOut led1(dp11); +DigitalOut led2(dp13); +DigitalOut led3(dp14); +DigitalOut led4(dp26); + + +//----------------------- +// Motor Library +Motor Right(dp18, dp17, dp25); // pwm,fwd,rev +Motor Left(dp2, dp4, dp6); // pwm,fwd,rev +//----------------------- + +Timeout timeout; + +void isr_timeout(void) +{ + Right.speed(0); + Left.speed(0); + + timeout.detach(); + timeout.attach_us(&isr_timeout, 1000 * 1000); +} + +void initialSpinner(void){ + + timeout.detach(); + timeout.attach_us(&isr_timeout, 1000 * 1000); + +} + +void mainSpinner(void) +{ +#ifdef DBG + pc.baud(9600); +#endif // DBG + + // IR data Monitor + led1 = 0; + led2 = 0; + led3 = 0; + led4 = 0; + + switch(ir_rx.getState()) { + case ReceiverIR::Idle: + led1 = 1; + break; + case ReceiverIR::Receiving: + led2 = 1; + break; + case ReceiverIR::Received: + led3 = 1; + break; + default: + led4 = 1; + break; + } + + if (ir_rx.getState() == ReceiverIR::Received) { + bitcountRx = ir_rx.getData(&formatRx, bufRx, sizeof(bufRx) * 8); + + if((formatRx == RemoteIR::SONY) && (bitcountRx == 16)) { + + timeout.detach(); + timeout.attach_us(&isr_timeout, 1000 * 1000); + + float xWork = (float)((int8_t)bufRx[0] / 8.0f); + float yWork = (float)((int8_t)bufRx[1] / 8.0f); + + // fukantai (-0.2 - 0.2) + if((-0.2 <= xWork) && (xWork <= 0.2)){xWork = 0;} + if((-0.2 <= yWork) && (yWork <= 0.2)){yWork = 0;} + + yWork = -yWork; // sousa wo hanten. + + float r = yWork + (xWork / 2.0); + float l = yWork - (xWork / 2.0); + + if(-1.0 > r) { + r = -1.0; + } + if( 1.0 < r) { + r = 1.0; + } + if(-1.0 > l) { + l = -1.0; + } + if( 1.0 < l) { + l = 1.0; + } + + +#ifdef DBG + pc.printf("x = %02d y = %02d |xWork = %1.1f yWork = %1.1f |r = %1.1f l = %1.1f \r\n",(int8_t)bufRx[0],(int8_t)bufRx[1],xWork,yWork,r,l); +#endif // DBG + + Right.speed(r); + Left.speed(-l); + + + + } + } +} +
diff -r 000000000000 -r 6825e25b7428 spinner.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spinner.h Wed Oct 16 02:45:27 2013 +0000 @@ -0,0 +1,9 @@ +#ifndef _SPINNER_H_ +#define _SPINNER_H_ + + + +void initialSpinner(void); +void mainSpinner(void); + +#endif // _SPINNER_H_ \ No newline at end of file