受け取りです.質問・アドバイスがあればどうぞ.
Dependencies: MultiSerial mbed
main.cpp@3:d4eff9dace7d, 2014-07-14 (annotated)
- Committer:
- lilac0112_1
- Date:
- Mon Jul 14 10:03:17 2014 +0000
- Revision:
- 3:d4eff9dace7d
- Parent:
- 1:b43b0cbff722
- Child:
- 4:541fdc451ab3
hokida????????????????????; ????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lilac0112_1 | 0:f38700ce12ea | 1 | #include "mbed.h" |
lilac0112_1 | 0:f38700ce12ea | 2 | #include "main.h"//ピン位置,main関数までの初期動作の詳細,変数,関数等 |
lilac0112_1 | 0:f38700ce12ea | 3 | |
lilac0112_1 | 3:d4eff9dace7d | 4 | BusIn mt(p6, p7, p8, p9, p10, p11); |
lilac0112_1 | 3:d4eff9dace7d | 5 | |
lilac0112_1 | 0:f38700ce12ea | 6 | extern bool GetBit(void); |
lilac0112_1 | 0:f38700ce12ea | 7 | extern DigitalOut LED[4]; |
lilac0112_1 | 0:f38700ce12ea | 8 | //上体回転関連 |
lilac0112_1 | 0:f38700ce12ea | 9 | extern DigitalOut Turn[2]; |
lilac0112_1 | 0:f38700ce12ea | 10 | extern DigitalIn TurnSW; |
lilac0112_1 | 0:f38700ce12ea | 11 | extern PwmOut TurnSpeed; |
lilac0112_1 | 0:f38700ce12ea | 12 | //パワーウィンドウ(腕)関連 |
lilac0112_1 | 0:f38700ce12ea | 13 | extern DigitalOut Hand[2][2]; |
lilac0112_1 | 0:f38700ce12ea | 14 | extern InterruptIn HandSW[3]; |
lilac0112_1 | 0:f38700ce12ea | 15 | extern Timeout Touch; |
lilac0112_1 | 0:f38700ce12ea | 16 | |
lilac0112_1 | 0:f38700ce12ea | 17 | //通信関連 |
lilac0112_1 | 0:f38700ce12ea | 18 | extern Serial pc; |
lilac0112_1 | 0:f38700ce12ea | 19 | extern Serial Xbee;//p13, p14 |
lilac0112_1 | 0:f38700ce12ea | 20 | extern volatile uint8_t INdata[DATA_NUM], EXdata[DATA_NUM]; |
lilac0112_1 | 0:f38700ce12ea | 21 | extern void TX(void); |
lilac0112_1 | 0:f38700ce12ea | 22 | extern void RX(void); |
lilac0112_1 | 3:d4eff9dace7d | 23 | |
lilac0112_1 | 3:d4eff9dace7d | 24 | void SetUp(void); |
lilac0112_1 | 3:d4eff9dace7d | 25 | |
lilac0112_1 | 0:f38700ce12ea | 26 | int main(void) { |
lilac0112_1 | 3:d4eff9dace7d | 27 | |
lilac0112_1 | 3:d4eff9dace7d | 28 | SetUp(); |
lilac0112_1 | 3:d4eff9dace7d | 29 | |
lilac0112_1 | 0:f38700ce12ea | 30 | while(1) { |
lilac0112_1 | 0:f38700ce12ea | 31 | //腕のプログラム |
lilac0112_1 | 3:d4eff9dace7d | 32 | |
lilac0112_1 | 0:f38700ce12ea | 33 | INdata[1]= ~mt;//調整用スイッチ |
lilac0112_1 | 3:d4eff9dace7d | 34 | |
lilac0112_1 | 3:d4eff9dace7d | 35 | if(GetBit(INdata[1], 2)==OFF) StopLeaving();//停止 |
lilac0112_1 | 3:d4eff9dace7d | 36 | |
lilac0112_1 | 0:f38700ce12ea | 37 | if((GetBit(INdata[1], 1)+GetBit(INdata[1], 2))==1){//同時押し防止 |
lilac0112_1 | 0:f38700ce12ea | 38 | if(GetBit(INdata[1], 1)==true) CenterCatch();//中央のリミットスイッチがうまく動作しなかった場合の保険 |
lilac0112_1 | 0:f38700ce12ea | 39 | if(GetBit(INdata[1], 2)==true){//腕を広げる動作はマニュアル操作 |
lilac0112_1 | 0:f38700ce12ea | 40 | StopCatching();//停止 |
lilac0112_1 | 0:f38700ce12ea | 41 | Touch.detach();//ワンショットタイマー停止 |
lilac0112_1 | 0:f38700ce12ea | 42 | Hand[R][Open] = Hand[L][Open] = GetBit(INdata[1], 2); |
lilac0112_1 | 0:f38700ce12ea | 43 | } |
lilac0112_1 | 0:f38700ce12ea | 44 | } |
lilac0112_1 | 3:d4eff9dace7d | 45 | |
lilac0112_1 | 3:d4eff9dace7d | 46 | if(((!HandSW[R])&&(!HandSW[L]))&&((Hand[R][Close]&&Hand[L][Close])==ON)){//どちらも押されたら停止 |
lilac0112_1 | 3:d4eff9dace7d | 47 | StopCatching();//停止 |
lilac0112_1 | 3:d4eff9dace7d | 48 | Touch.detach();//ワンショットタイマー停止 |
lilac0112_1 | 3:d4eff9dace7d | 49 | } |
lilac0112_1 | 0:f38700ce12ea | 50 | //上体回転 |
lilac0112_1 | 3:d4eff9dace7d | 51 | |
lilac0112_1 | 0:f38700ce12ea | 52 | INdata[3] = ~mt;//調整用スイッチ |
lilac0112_1 | 3:d4eff9dace7d | 53 | |
lilac0112_1 | 0:f38700ce12ea | 54 | Turn[CW] = Turn[CCW] = OFF;//停止 |
lilac0112_1 | 3:d4eff9dace7d | 55 | |
lilac0112_1 | 0:f38700ce12ea | 56 | if((GetBit(INdata[3], 1)+GetBit(INdata[3], 2))==1){//同時押し防止 |
lilac0112_1 | 0:f38700ce12ea | 57 | if(GetBit(INdata[3], 1)&&(TurnSW)){ |
lilac0112_1 | 0:f38700ce12ea | 58 | Turn[CCW] = ON;//押されていて,かつリミットスイッチが押されていなかったら左回転 |
lilac0112_1 | 0:f38700ce12ea | 59 | } |
lilac0112_1 | 3:d4eff9dace7d | 60 | |
lilac0112_1 | 0:f38700ce12ea | 61 | if(GetBit(INdata[3], 2)){ |
lilac0112_1 | 0:f38700ce12ea | 62 | Turn[CW] = ON;//押されたら右回転 |
lilac0112_1 | 0:f38700ce12ea | 63 | } |
lilac0112_1 | 0:f38700ce12ea | 64 | } |
lilac0112_1 | 0:f38700ce12ea | 65 | } |
lilac0112_1 | 0:f38700ce12ea | 66 | } |
lilac0112_1 | 3:d4eff9dace7d | 67 | |
lilac0112_1 | 3:d4eff9dace7d | 68 | void SetUp(void){ |
lilac0112_1 | 3:d4eff9dace7d | 69 | |
lilac0112_1 | 3:d4eff9dace7d | 70 | uint8_t i=1; |
lilac0112_1 | 3:d4eff9dace7d | 71 | |
lilac0112_1 | 3:d4eff9dace7d | 72 | mt.mode(PullUp); |
lilac0112_1 | 3:d4eff9dace7d | 73 | |
lilac0112_1 | 3:d4eff9dace7d | 74 | TurnSpeed = TURN_REV;//上体回転のPWM |
lilac0112_1 | 3:d4eff9dace7d | 75 | TurnSW.mode(PullUp); |
lilac0112_1 | 3:d4eff9dace7d | 76 | |
lilac0112_1 | 3:d4eff9dace7d | 77 | HandSW[R].mode(PullUp); |
lilac0112_1 | 3:d4eff9dace7d | 78 | HandSW[L].mode(PullUp); |
lilac0112_1 | 3:d4eff9dace7d | 79 | HandSW[C].mode(PullUp); |
lilac0112_1 | 3:d4eff9dace7d | 80 | HandSW[R].rise(RightCatch);//立ち上がり |
lilac0112_1 | 3:d4eff9dace7d | 81 | HandSW[L].rise(LeftCatch);//立ち上がり |
lilac0112_1 | 3:d4eff9dace7d | 82 | HandSW[C].rise(CenterCatch);//立ち上がり |
lilac0112_1 | 3:d4eff9dace7d | 83 | |
lilac0112_1 | 3:d4eff9dace7d | 84 | Xbee.attach(&RX, Serial::RxIrq); |
lilac0112_1 | 3:d4eff9dace7d | 85 | Xbee.attach(&TX, Serial::TxIrq); |
lilac0112_1 | 3:d4eff9dace7d | 86 | |
lilac0112_1 | 3:d4eff9dace7d | 87 | Xbee.putc(i);//送信開始 |
lilac0112_1 | 3:d4eff9dace7d | 88 | i = Xbee.getc();//受信開始 |
lilac0112_1 | 3:d4eff9dace7d | 89 | } |