YOZAKURA ARM program, usb serial
Dependencies: Dynamixel SerialHalfDuplex mbed
main.cpp@1:bf4d524625f5, 2015-04-24 (annotated)
- Committer:
- yusuke_kyo
- Date:
- Fri Apr 24 17:14:48 2015 +0000
- Revision:
- 1:bf4d524625f5
- Parent:
- 0:8822acabe470
- Child:
- 2:f0efe1d10f8a
Thermo_data[100]
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yusuke_kyo | 0:8822acabe470 | 1 | /*YOZAKURAのアームコード |
yusuke_kyo | 0:8822acabe470 | 2 | シリアル通信で送るデータ S_Data={linearD[4],pitchD[4],yawD[4],ThermoD1[16],ThermoD2[16],CO2[4]} 計48bytes |
yusuke_kyo | 0:8822acabe470 | 3 | シリアル通信で受け取るデータ R_Data={mode[2bit],linear_ref[2bit],pitch_ref[2bit],yaw_ref[2bit]} 計1byte |
yusuke_kyo | 0:8822acabe470 | 4 | */ |
yusuke_kyo | 0:8822acabe470 | 5 | |
yusuke_kyo | 0:8822acabe470 | 6 | #include "mbed.h" |
yusuke_kyo | 0:8822acabe470 | 7 | |
yusuke_kyo | 0:8822acabe470 | 8 | Serial pc(USBTX, USBRX); // tx, rx |
yusuke_kyo | 0:8822acabe470 | 9 | DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); |
yusuke_kyo | 0:8822acabe470 | 10 | |
yusuke_kyo | 0:8822acabe470 | 11 | /*--Dynamixel:begin-----------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 12 | #include "AX12.h" |
yusuke_kyo | 0:8822acabe470 | 13 | #include "MX28.h" |
yusuke_kyo | 0:8822acabe470 | 14 | |
yusuke_kyo | 0:8822acabe470 | 15 | DigitalOut low(p16); DigitalOut RelaySwitch(p18); |
yusuke_kyo | 0:8822acabe470 | 16 | |
yusuke_kyo | 0:8822acabe470 | 17 | AX12 linear (p13, p14, 0, 1000000); //直動Dynamixel |
yusuke_kyo | 0:8822acabe470 | 18 | MX28 pitch (p13, p14, 1, 1000000); //ピッチDynamixel |
yusuke_kyo | 0:8822acabe470 | 19 | MX28 yaw (p13, p14, 2, 1000000); //ヨーDynamixel |
yusuke_kyo | 0:8822acabe470 | 20 | |
yusuke_kyo | 0:8822acabe470 | 21 | int linear_goal, pitch_goal, yaw_goal; |
yusuke_kyo | 0:8822acabe470 | 22 | |
yusuke_kyo | 0:8822acabe470 | 23 | //最小値,最大値,角速度,初期値を指定[unit:degree] |
yusuke_kyo | 0:8822acabe470 | 24 | //MX:MultiTurnモードでは-2520°~2520°(SetGoalの書き換え不要) |
yusuke_kyo | 0:8822acabe470 | 25 | int linear_min = 100; int linear_MAX = 300; float linear_Speed=0.1; int linear_Init = linear_MAX; |
yusuke_kyo | 0:8822acabe470 | 26 | int pitch_min = 172; int pitch_MAX = 334; float pitch_Speed=0.2; int pitch_Init = pitch_MAX; |
yusuke_kyo | 0:8822acabe470 | 27 | int yaw_min = 360; int yaw_MAX = 360; float yaw_Speed=0.2; int yaw_Init = 0; //MultiTurnモード |
yusuke_kyo | 0:8822acabe470 | 28 | |
yusuke_kyo | 0:8822acabe470 | 29 | void Dyna_init() { |
yusuke_kyo | 0:8822acabe470 | 30 | // low = 0; RelaySwitch = 1; |
yusuke_kyo | 0:8822acabe470 | 31 | linear.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 32 | pitch.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 33 | yaw.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 34 | linear.SetCWLimit(linear_min); linear.SetCCWLimit(linear_MAX); |
yusuke_kyo | 0:8822acabe470 | 35 | linear.SetCRSpeed(linear_Speed); linear_goal=linear_Init; |
yusuke_kyo | 0:8822acabe470 | 36 | pitch.SetCWLimit(pitch_min); pitch.SetCCWLimit(pitch_MAX); |
yusuke_kyo | 0:8822acabe470 | 37 | pitch.SetCRSpeed(pitch_Speed); pitch_goal=pitch_Init; |
yusuke_kyo | 0:8822acabe470 | 38 | yaw.SetCWLimit(yaw_min); yaw.SetCCWLimit(yaw_MAX); |
yusuke_kyo | 0:8822acabe470 | 39 | yaw.SetCRSpeed(yaw_Speed); yaw_goal=yaw_Init; |
yusuke_kyo | 0:8822acabe470 | 40 | wait(1); |
yusuke_kyo | 0:8822acabe470 | 41 | } |
yusuke_kyo | 0:8822acabe470 | 42 | |
yusuke_kyo | 0:8822acabe470 | 43 | void Dyna_GetData(char* data) { |
yusuke_kyo | 0:8822acabe470 | 44 | float lP, lV, pP, pC, yP, yC; |
yusuke_kyo | 0:8822acabe470 | 45 | |
yusuke_kyo | 0:8822acabe470 | 46 | lP = linear.GetPosition(); lV = linear.GetVolts(); |
yusuke_kyo | 0:8822acabe470 | 47 | pP = pitch.GetPosition(); pC = pitch.GetCurrent(); |
yusuke_kyo | 0:8822acabe470 | 48 | yP = yaw.GetPosition(); yC = yaw.GetCurrent(); |
yusuke_kyo | 0:8822acabe470 | 49 | |
yusuke_kyo | 0:8822acabe470 | 50 | linear_goal=lP; pitch_goal=pP; yaw_goal=yP; //現在角度を目標値に設定 |
yusuke_kyo | 0:8822acabe470 | 51 | sprintf(data,"%4.1f %4.1f %4.1f %4.1f %4.1f %4.1f ",lP,lV,pP,pC,yP,yC); |
yusuke_kyo | 0:8822acabe470 | 52 | } |
yusuke_kyo | 0:8822acabe470 | 53 | |
yusuke_kyo | 0:8822acabe470 | 54 | void Dyna_SetGoal(int linear_mode, int pitch_mode, int yaw_mode) { |
yusuke_kyo | 0:8822acabe470 | 55 | switch(linear_mode){ |
yusuke_kyo | 0:8822acabe470 | 56 | case 0: break; |
yusuke_kyo | 0:8822acabe470 | 57 | case 1: linear.SetTorqueLimit(1); linear_goal++; break; |
yusuke_kyo | 0:8822acabe470 | 58 | case 2: linear.SetTorqueLimit(1); linear_goal--; break; |
yusuke_kyo | 0:8822acabe470 | 59 | } |
yusuke_kyo | 0:8822acabe470 | 60 | if(linear_goal>linear_MAX) linear_goal=linear_MAX; |
yusuke_kyo | 0:8822acabe470 | 61 | if(linear_goal<linear_min) linear_goal=linear_min; |
yusuke_kyo | 0:8822acabe470 | 62 | linear.SetGoal(linear_goal); |
yusuke_kyo | 0:8822acabe470 | 63 | |
yusuke_kyo | 0:8822acabe470 | 64 | switch(pitch_mode){ |
yusuke_kyo | 0:8822acabe470 | 65 | case 0: break; |
yusuke_kyo | 0:8822acabe470 | 66 | case 1: pitch_goal-=5; |
yusuke_kyo | 0:8822acabe470 | 67 | if(pitch_goal>pitch_MAX) pitch_goal=pitch_MAX; |
yusuke_kyo | 0:8822acabe470 | 68 | break; |
yusuke_kyo | 0:8822acabe470 | 69 | case 2: pitch_goal+=5; |
yusuke_kyo | 0:8822acabe470 | 70 | if(pitch_goal<pitch_min) pitch_goal=pitch_min; |
yusuke_kyo | 0:8822acabe470 | 71 | break; |
yusuke_kyo | 0:8822acabe470 | 72 | } |
yusuke_kyo | 0:8822acabe470 | 73 | if(pitch_goal>pitch_MAX) pitch_goal=pitch_MAX; |
yusuke_kyo | 0:8822acabe470 | 74 | if(pitch_goal<pitch_min) pitch_goal=pitch_min; |
yusuke_kyo | 0:8822acabe470 | 75 | pitch.SetGoal(pitch_goal); |
yusuke_kyo | 0:8822acabe470 | 76 | |
yusuke_kyo | 0:8822acabe470 | 77 | switch(yaw_mode){ |
yusuke_kyo | 0:8822acabe470 | 78 | case 0: break; |
yusuke_kyo | 0:8822acabe470 | 79 | case 1: yaw_goal-=5; break; |
yusuke_kyo | 0:8822acabe470 | 80 | case 2: yaw_goal+=5; break; |
yusuke_kyo | 0:8822acabe470 | 81 | } |
yusuke_kyo | 0:8822acabe470 | 82 | if(pitch_goal>2520) pitch_goal=2520; |
yusuke_kyo | 0:8822acabe470 | 83 | if(pitch_goal<-2520) pitch_goal=-2520; |
yusuke_kyo | 0:8822acabe470 | 84 | yaw.SetGoal(yaw_goal); |
yusuke_kyo | 0:8822acabe470 | 85 | } |
yusuke_kyo | 0:8822acabe470 | 86 | |
yusuke_kyo | 0:8822acabe470 | 87 | void Dyna_home_position() { |
yusuke_kyo | 0:8822acabe470 | 88 | linear.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 89 | pitch.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 90 | yaw.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 91 | float lp; |
yusuke_kyo | 0:8822acabe470 | 92 | linear.SetGoal(linear_Init); |
yusuke_kyo | 0:8822acabe470 | 93 | lp=linear.GetPosition(); |
yusuke_kyo | 0:8822acabe470 | 94 | if(lp > linear_MAX - 30) { //ある程度縮んだら |
yusuke_kyo | 0:8822acabe470 | 95 | pitch.SetGoal(pitch_Init); |
yusuke_kyo | 0:8822acabe470 | 96 | yaw.SetGoal(yaw_Init); |
yusuke_kyo | 0:8822acabe470 | 97 | } |
yusuke_kyo | 0:8822acabe470 | 98 | } |
yusuke_kyo | 0:8822acabe470 | 99 | |
yusuke_kyo | 0:8822acabe470 | 100 | void Dyna_reset() { |
yusuke_kyo | 0:8822acabe470 | 101 | // RelaySwitch = 0; |
yusuke_kyo | 0:8822acabe470 | 102 | linear.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 103 | pitch.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 104 | yaw.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 105 | |
yusuke_kyo | 0:8822acabe470 | 106 | wait_ms(10); |
yusuke_kyo | 0:8822acabe470 | 107 | |
yusuke_kyo | 0:8822acabe470 | 108 | // RelaySwitch = 1; |
yusuke_kyo | 0:8822acabe470 | 109 | linear.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 110 | pitch.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 111 | yaw.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 112 | } |
yusuke_kyo | 0:8822acabe470 | 113 | |
yusuke_kyo | 0:8822acabe470 | 114 | void Dyna_end() { |
yusuke_kyo | 0:8822acabe470 | 115 | // RelaySwitch = 0; |
yusuke_kyo | 0:8822acabe470 | 116 | linear.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 117 | pitch.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 118 | yaw.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 119 | } |
yusuke_kyo | 0:8822acabe470 | 120 | /*--Dynamixel:end-----------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 121 | |
yusuke_kyo | 0:8822acabe470 | 122 | |
yusuke_kyo | 0:8822acabe470 | 123 | /*--Thermal_Sensor:begin----------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 124 | /*MEMS非接触温度センサ:形D6T-44L-06 4×4素子タイプ*/ |
yusuke_kyo | 0:8822acabe470 | 125 | /*データシート:http://www.omron.co.jp/ecb/products/sensor/special/mems/pdf/AN-D6T-01JP_r2.pdf*/ |
yusuke_kyo | 0:8822acabe470 | 126 | |
yusuke_kyo | 0:8822acabe470 | 127 | I2C MEMS1(p9, p10); // sda, scl |
yusuke_kyo | 0:8822acabe470 | 128 | I2C MEMS2(p28, p27); // sda, scl |
yusuke_kyo | 0:8822acabe470 | 129 | |
yusuke_kyo | 0:8822acabe470 | 130 | #define D6T_addr 0x14 |
yusuke_kyo | 0:8822acabe470 | 131 | #define D6T_cmd 0x4c |
yusuke_kyo | 0:8822acabe470 | 132 | |
yusuke_kyo | 0:8822acabe470 | 133 | #define THERMO_DEBUG 1 |
yusuke_kyo | 0:8822acabe470 | 134 | |
yusuke_kyo | 0:8822acabe470 | 135 | void GetThermo(char* data) { |
yusuke_kyo | 0:8822acabe470 | 136 | char con[10]; |
yusuke_kyo | 0:8822acabe470 | 137 | |
yusuke_kyo | 0:8822acabe470 | 138 | /*MEMS1*/ |
yusuke_kyo | 0:8822acabe470 | 139 | char I2C_rd1[64]; // 生データ |
yusuke_kyo | 0:8822acabe470 | 140 | short datr1[16]; // 16点 温度データ(10倍整数) |
yusuke_kyo | 0:8822acabe470 | 141 | short PTAT1; // センサ内部PTAT温度データ(10倍整数) |
yusuke_kyo | 0:8822acabe470 | 142 | double dt1[16]; // 16点 温度データ |
yusuke_kyo | 0:8822acabe470 | 143 | short d_PTAT1; // センサ内部PTAT温度データ |
yusuke_kyo | 0:8822acabe470 | 144 | |
yusuke_kyo | 0:8822acabe470 | 145 | int i,j; |
yusuke_kyo | 0:8822acabe470 | 146 | int itemp; |
yusuke_kyo | 0:8822acabe470 | 147 | |
yusuke_kyo | 0:8822acabe470 | 148 | //// measure |
yusuke_kyo | 0:8822acabe470 | 149 | MEMS1.start(); |
yusuke_kyo | 0:8822acabe470 | 150 | MEMS1.write(D6T_addr); |
yusuke_kyo | 0:8822acabe470 | 151 | MEMS1.write(D6T_cmd); |
yusuke_kyo | 0:8822acabe470 | 152 | // Repeated Start condition |
yusuke_kyo | 0:8822acabe470 | 153 | MEMS1.read(D6T_addr,I2C_rd1,35); |
yusuke_kyo | 0:8822acabe470 | 154 | // if(check_PEC(I2C_rd) == -1) continue; // error |
yusuke_kyo | 0:8822acabe470 | 155 | for(i=0,j=0;i<17;i++){ |
yusuke_kyo | 0:8822acabe470 | 156 | itemp = (I2C_rd1[j++] & 0xff); |
yusuke_kyo | 0:8822acabe470 | 157 | itemp += I2C_rd1[j++] * 256; |
yusuke_kyo | 0:8822acabe470 | 158 | if(i == 0) PTAT1 = itemp; |
yusuke_kyo | 0:8822acabe470 | 159 | else datr1[i-1] = itemp; |
yusuke_kyo | 0:8822acabe470 | 160 | } |
yusuke_kyo | 0:8822acabe470 | 161 | for(i=0;i<16;i++){ |
yusuke_kyo | 0:8822acabe470 | 162 | dt1[i] = 0.1 * datr1[i]; |
yusuke_kyo | 0:8822acabe470 | 163 | } |
yusuke_kyo | 0:8822acabe470 | 164 | for(int i=0;i<16;i++){ |
yusuke_kyo | 0:8822acabe470 | 165 | sprintf(con,"%3.1f ",dt1[i]); |
yusuke_kyo | 0:8822acabe470 | 166 | strcat(data,con); |
yusuke_kyo | 0:8822acabe470 | 167 | } |
yusuke_kyo | 0:8822acabe470 | 168 | d_PTAT1 = 0.1 * PTAT1; |
yusuke_kyo | 0:8822acabe470 | 169 | wait(0.1); |
yusuke_kyo | 0:8822acabe470 | 170 | /*MEMS1*/ |
yusuke_kyo | 0:8822acabe470 | 171 | |
yusuke_kyo | 0:8822acabe470 | 172 | /*MEMS2*/ |
yusuke_kyo | 0:8822acabe470 | 173 | char I2C_rd2[64]; // 生データ |
yusuke_kyo | 0:8822acabe470 | 174 | short datr2[16]; // 16点 温度データ(10倍整数) |
yusuke_kyo | 0:8822acabe470 | 175 | short PTAT2; // センサ内部PTAT温度データ(10倍整数) |
yusuke_kyo | 0:8822acabe470 | 176 | double dt2[16]; // 16点 温度データ |
yusuke_kyo | 0:8822acabe470 | 177 | short d_PTAT2; // センサ内部PTAT温度データ |
yusuke_kyo | 0:8822acabe470 | 178 | |
yusuke_kyo | 0:8822acabe470 | 179 | //// measure |
yusuke_kyo | 0:8822acabe470 | 180 | MEMS2.start(); |
yusuke_kyo | 0:8822acabe470 | 181 | MEMS2.write(D6T_addr); |
yusuke_kyo | 0:8822acabe470 | 182 | MEMS2.write(D6T_cmd); |
yusuke_kyo | 0:8822acabe470 | 183 | // Repeated Start condition |
yusuke_kyo | 0:8822acabe470 | 184 | MEMS2.read(D6T_addr,I2C_rd2,35); |
yusuke_kyo | 0:8822acabe470 | 185 | // if(check_PEC(I2C_rd) == -1) continue; // error |
yusuke_kyo | 0:8822acabe470 | 186 | for(i=0,j=0;i<17;i++){ |
yusuke_kyo | 0:8822acabe470 | 187 | itemp = (I2C_rd2[j++] & 0xff); |
yusuke_kyo | 0:8822acabe470 | 188 | itemp += I2C_rd2[j++] * 256; |
yusuke_kyo | 0:8822acabe470 | 189 | if(i == 0) PTAT2 = itemp; |
yusuke_kyo | 0:8822acabe470 | 190 | else datr2[i-1] = itemp; |
yusuke_kyo | 0:8822acabe470 | 191 | } |
yusuke_kyo | 0:8822acabe470 | 192 | for(i=0;i<16;i++){ |
yusuke_kyo | 0:8822acabe470 | 193 | dt2[i] = 0.1 * datr2[i]; |
yusuke_kyo | 0:8822acabe470 | 194 | if(i%4==0) printf("\n"); |
yusuke_kyo | 0:8822acabe470 | 195 | printf("%3.1f ",dt2[i]); |
yusuke_kyo | 0:8822acabe470 | 196 | } |
yusuke_kyo | 0:8822acabe470 | 197 | for(int i=0;i<16;i++){ |
yusuke_kyo | 0:8822acabe470 | 198 | sprintf(con,"%3.1f ",dt2[i]); |
yusuke_kyo | 0:8822acabe470 | 199 | strcat(data,con); |
yusuke_kyo | 0:8822acabe470 | 200 | } |
yusuke_kyo | 0:8822acabe470 | 201 | d_PTAT2 = 0.1 * PTAT2; |
yusuke_kyo | 0:8822acabe470 | 202 | wait(0.1); |
yusuke_kyo | 0:8822acabe470 | 203 | /*MEMS2*/ |
yusuke_kyo | 0:8822acabe470 | 204 | } |
yusuke_kyo | 0:8822acabe470 | 205 | /*--Thermal_Sensor:end------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 206 | |
yusuke_kyo | 0:8822acabe470 | 207 | |
yusuke_kyo | 0:8822acabe470 | 208 | /*--CO2_Sensor:begin--------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 209 | /*CO2センサモジュール:A051020-AQ6B-01*/ |
yusuke_kyo | 0:8822acabe470 | 210 | /*データシート:http://www.fisinc.co.jp/common/pdf/A051020-AQ6.pdf*/ |
yusuke_kyo | 0:8822acabe470 | 211 | /*参考 外気:396.0[ppm](2013年) 呼気:13,200[ppm] ※このセンサで測れるのは3000[ppm]まで*/ |
yusuke_kyo | 0:8822acabe470 | 212 | #include "mbed.h" |
yusuke_kyo | 0:8822acabe470 | 213 | |
yusuke_kyo | 0:8822acabe470 | 214 | AnalogIn ain(p20); |
yusuke_kyo | 0:8822acabe470 | 215 | |
yusuke_kyo | 0:8822acabe470 | 216 | #define CO2_DEBUG 1 |
yusuke_kyo | 0:8822acabe470 | 217 | |
yusuke_kyo | 0:8822acabe470 | 218 | float GetCO2() { |
yusuke_kyo | 0:8822acabe470 | 219 | float v; //生データ:電圧 |
yusuke_kyo | 0:8822acabe470 | 220 | float sensor_v,CO2; |
yusuke_kyo | 0:8822acabe470 | 221 | |
yusuke_kyo | 0:8822acabe470 | 222 | v = ain.read()*3.3; |
yusuke_kyo | 0:8822acabe470 | 223 | sensor_v = v * 5.0/3.3; //電圧レベルを合わせる |
yusuke_kyo | 0:8822acabe470 | 224 | CO2 = sensor_v * 1000 + 400; //データシートより |
yusuke_kyo | 0:8822acabe470 | 225 | |
yusuke_kyo | 0:8822acabe470 | 226 | if(CO2_DEBUG) printf("\nCO2:%4.1f\n",CO2); |
yusuke_kyo | 0:8822acabe470 | 227 | |
yusuke_kyo | 0:8822acabe470 | 228 | return(CO2); |
yusuke_kyo | 0:8822acabe470 | 229 | } |
yusuke_kyo | 0:8822acabe470 | 230 | /*--CO2_Sensor:end----------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 231 | |
yusuke_kyo | 0:8822acabe470 | 232 | |
yusuke_kyo | 0:8822acabe470 | 233 | /*--------------- |
yusuke_kyo | 0:8822acabe470 | 234 | MAIN ROOP |
yusuke_kyo | 0:8822acabe470 | 235 | ----------------*/ |
yusuke_kyo | 0:8822acabe470 | 236 | |
yusuke_kyo | 0:8822acabe470 | 237 | int main() { |
yusuke_kyo | 0:8822acabe470 | 238 | char Dyna_data[100]; |
yusuke_kyo | 0:8822acabe470 | 239 | float CO2_data; |
yusuke_kyo | 0:8822acabe470 | 240 | |
yusuke_kyo | 0:8822acabe470 | 241 | Dyna_init(); |
yusuke_kyo | 0:8822acabe470 | 242 | |
yusuke_kyo | 0:8822acabe470 | 243 | char Send_data[200]; |
yusuke_kyo | 0:8822acabe470 | 244 | int Read_data; |
yusuke_kyo | 0:8822acabe470 | 245 | int Joy_mode, linear_mode, pitch_mode, yaw_mode; |
yusuke_kyo | 0:8822acabe470 | 246 | |
yusuke_kyo | 0:8822acabe470 | 247 | while(1) { |
yusuke_kyo | 0:8822acabe470 | 248 | |
yusuke_kyo | 0:8822acabe470 | 249 | Read_data=pc.getc(); |
yusuke_kyo | 0:8822acabe470 | 250 | wait_ms(1); |
yusuke_kyo | 0:8822acabe470 | 251 | Joy_mode = Read_data & 0x03; //ジョイスティックのモード判定 |
yusuke_kyo | 0:8822acabe470 | 252 | |
yusuke_kyo | 0:8822acabe470 | 253 | switch(Joy_mode){ |
yusuke_kyo | 0:8822acabe470 | 254 | case 0: //通常モード |
yusuke_kyo | 0:8822acabe470 | 255 | myled1=0; myled2=0; myled3=0; myled4=0; |
yusuke_kyo | 0:8822acabe470 | 256 | /*--Dynamixel:begin---------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 257 | //Dynamixelへの命令を判定 |
yusuke_kyo | 0:8822acabe470 | 258 | linear_mode = Read_data & 0x0c; linear_mode = linear_mode >> 2; |
yusuke_kyo | 0:8822acabe470 | 259 | pitch_mode = Read_data & 0x30; pitch_mode = pitch_mode >> 4; |
yusuke_kyo | 0:8822acabe470 | 260 | yaw_mode = Read_data & 0xc0; yaw_mode = yaw_mode >> 6; |
yusuke_kyo | 0:8822acabe470 | 261 | |
yusuke_kyo | 0:8822acabe470 | 262 | //現在の角度・電圧・電流を取得 |
yusuke_kyo | 0:8822acabe470 | 263 | myled1=1; |
yusuke_kyo | 0:8822acabe470 | 264 | Dyna_GetData(Dyna_data); |
yusuke_kyo | 0:8822acabe470 | 265 | myled1=0; |
yusuke_kyo | 0:8822acabe470 | 266 | |
yusuke_kyo | 0:8822acabe470 | 267 | //目標角度を変更 |
yusuke_kyo | 0:8822acabe470 | 268 | myled2=1; |
yusuke_kyo | 0:8822acabe470 | 269 | Dyna_SetGoal(linear_mode, pitch_mode, yaw_mode); |
yusuke_kyo | 0:8822acabe470 | 270 | myled2=0; |
yusuke_kyo | 0:8822acabe470 | 271 | /*--Dynamixel:end------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 272 | |
yusuke_kyo | 0:8822acabe470 | 273 | /*--Thermal_Sensor:begin-----------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 274 | //値を取得 |
yusuke_kyo | 0:8822acabe470 | 275 | myled3=1; |
yusuke_kyo | 1:bf4d524625f5 | 276 | char Thermo_data[100]; |
yusuke_kyo | 0:8822acabe470 | 277 | GetThermo(Thermo_data); |
yusuke_kyo | 0:8822acabe470 | 278 | /*--Thermal_Sensor:end-------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 279 | |
yusuke_kyo | 0:8822acabe470 | 280 | /*--CO2_Sensor:begin---------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 281 | //値を取得 |
yusuke_kyo | 0:8822acabe470 | 282 | CO2_data=GetCO2(); |
yusuke_kyo | 0:8822acabe470 | 283 | myled3=0; |
yusuke_kyo | 0:8822acabe470 | 284 | /*--CO2_Sensor:end-----------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 285 | |
yusuke_kyo | 0:8822acabe470 | 286 | //値を送信 |
yusuke_kyo | 0:8822acabe470 | 287 | myled4=1; |
yusuke_kyo | 0:8822acabe470 | 288 | sprintf(Send_data,"%s%s%f",Dyna_data,Thermo_data,CO2_data); |
yusuke_kyo | 0:8822acabe470 | 289 | printf("%s\n",Send_data); |
yusuke_kyo | 0:8822acabe470 | 290 | myled4=0; |
yusuke_kyo | 0:8822acabe470 | 291 | break; |
yusuke_kyo | 0:8822acabe470 | 292 | |
yusuke_kyo | 0:8822acabe470 | 293 | case 1: //ホームポジション |
yusuke_kyo | 0:8822acabe470 | 294 | myled1=1; myled2=0; myled3=0; myled4=1; Dyna_home_position(); break; |
yusuke_kyo | 0:8822acabe470 | 295 | |
yusuke_kyo | 0:8822acabe470 | 296 | case 2: //リセット |
yusuke_kyo | 0:8822acabe470 | 297 | myled1=0; myled2=1; myled3=1; myled4=0; Dyna_reset(); break; |
yusuke_kyo | 0:8822acabe470 | 298 | |
yusuke_kyo | 0:8822acabe470 | 299 | case 3: //終了 |
yusuke_kyo | 0:8822acabe470 | 300 | myled1=1; myled2=1; myled3=1; myled4=1; Dyna_end(); break; |
yusuke_kyo | 0:8822acabe470 | 301 | } |
yusuke_kyo | 0:8822acabe470 | 302 | } |
yusuke_kyo | 0:8822acabe470 | 303 | } |