Modify ota's code
Dependencies: Dynamixel SerialHalfDuplex mbed
Fork of YOZAKURA_ARM_USB_0425 by
main.cpp@3:6a932d0aac7d, 2015-04-25 (annotated)
- Committer:
- yusuke_kyo
- Date:
- Sat Apr 25 06:08:18 2015 +0000
- Revision:
- 3:6a932d0aac7d
- Parent:
- 2:f0efe1d10f8a
- Child:
- 4:d9ea010641ab
thermal_sensor
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 | 3:6a932d0aac7d | 57 | case 1: linear.SetTorqueLimit(1); linear_goal-=2; break; |
yusuke_kyo | 3:6a932d0aac7d | 58 | case 2: linear.SetTorqueLimit(1); linear_goal+=2; 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 | 3:6a932d0aac7d | 66 | case 1: pitch_goal-=3; break; |
yusuke_kyo | 3:6a932d0aac7d | 67 | case 2: pitch_goal+=3; break; |
yusuke_kyo | 0:8822acabe470 | 68 | } |
yusuke_kyo | 0:8822acabe470 | 69 | if(pitch_goal>pitch_MAX) pitch_goal=pitch_MAX; |
yusuke_kyo | 0:8822acabe470 | 70 | if(pitch_goal<pitch_min) pitch_goal=pitch_min; |
yusuke_kyo | 0:8822acabe470 | 71 | pitch.SetGoal(pitch_goal); |
yusuke_kyo | 0:8822acabe470 | 72 | |
yusuke_kyo | 0:8822acabe470 | 73 | switch(yaw_mode){ |
yusuke_kyo | 0:8822acabe470 | 74 | case 0: break; |
yusuke_kyo | 3:6a932d0aac7d | 75 | case 1: yaw_goal-=3; break; |
yusuke_kyo | 3:6a932d0aac7d | 76 | case 2: yaw_goal+=3; break; |
yusuke_kyo | 0:8822acabe470 | 77 | } |
yusuke_kyo | 0:8822acabe470 | 78 | if(pitch_goal>2520) pitch_goal=2520; |
yusuke_kyo | 0:8822acabe470 | 79 | if(pitch_goal<-2520) pitch_goal=-2520; |
yusuke_kyo | 0:8822acabe470 | 80 | yaw.SetGoal(yaw_goal); |
yusuke_kyo | 0:8822acabe470 | 81 | } |
yusuke_kyo | 0:8822acabe470 | 82 | |
yusuke_kyo | 0:8822acabe470 | 83 | void Dyna_home_position() { |
yusuke_kyo | 0:8822acabe470 | 84 | linear.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 85 | pitch.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 86 | yaw.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 87 | float lp; |
yusuke_kyo | 0:8822acabe470 | 88 | linear.SetGoal(linear_Init); |
yusuke_kyo | 0:8822acabe470 | 89 | lp=linear.GetPosition(); |
yusuke_kyo | 0:8822acabe470 | 90 | if(lp > linear_MAX - 30) { //ある程度縮んだら |
yusuke_kyo | 0:8822acabe470 | 91 | pitch.SetGoal(pitch_Init); |
yusuke_kyo | 0:8822acabe470 | 92 | yaw.SetGoal(yaw_Init); |
yusuke_kyo | 0:8822acabe470 | 93 | } |
yusuke_kyo | 0:8822acabe470 | 94 | } |
yusuke_kyo | 0:8822acabe470 | 95 | |
yusuke_kyo | 0:8822acabe470 | 96 | void Dyna_reset() { |
yusuke_kyo | 0:8822acabe470 | 97 | // RelaySwitch = 0; |
yusuke_kyo | 0:8822acabe470 | 98 | linear.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 99 | pitch.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 100 | yaw.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 101 | |
yusuke_kyo | 2:f0efe1d10f8a | 102 | wait(0.1); |
yusuke_kyo | 0:8822acabe470 | 103 | |
yusuke_kyo | 0:8822acabe470 | 104 | // RelaySwitch = 1; |
yusuke_kyo | 0:8822acabe470 | 105 | linear.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 106 | pitch.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 107 | yaw.SetTorqueLimit(1); |
yusuke_kyo | 0:8822acabe470 | 108 | } |
yusuke_kyo | 0:8822acabe470 | 109 | |
yusuke_kyo | 0:8822acabe470 | 110 | void Dyna_end() { |
yusuke_kyo | 0:8822acabe470 | 111 | // RelaySwitch = 0; |
yusuke_kyo | 0:8822acabe470 | 112 | linear.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 113 | pitch.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 114 | yaw.SetTorqueLimit(0); |
yusuke_kyo | 0:8822acabe470 | 115 | } |
yusuke_kyo | 0:8822acabe470 | 116 | /*--Dynamixel:end-----------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 117 | |
yusuke_kyo | 0:8822acabe470 | 118 | |
yusuke_kyo | 0:8822acabe470 | 119 | /*--Thermal_Sensor:begin----------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 120 | /*MEMS非接触温度センサ:形D6T-44L-06 4×4素子タイプ*/ |
yusuke_kyo | 0:8822acabe470 | 121 | /*データシート:http://www.omron.co.jp/ecb/products/sensor/special/mems/pdf/AN-D6T-01JP_r2.pdf*/ |
yusuke_kyo | 0:8822acabe470 | 122 | |
yusuke_kyo | 0:8822acabe470 | 123 | I2C MEMS1(p9, p10); // sda, scl |
yusuke_kyo | 0:8822acabe470 | 124 | I2C MEMS2(p28, p27); // sda, scl |
yusuke_kyo | 0:8822acabe470 | 125 | |
yusuke_kyo | 0:8822acabe470 | 126 | #define D6T_addr 0x14 |
yusuke_kyo | 0:8822acabe470 | 127 | #define D6T_cmd 0x4c |
yusuke_kyo | 0:8822acabe470 | 128 | |
yusuke_kyo | 3:6a932d0aac7d | 129 | #define THERMO_DEBUG 1 |
yusuke_kyo | 3:6a932d0aac7d | 130 | |
yusuke_kyo | 3:6a932d0aac7d | 131 | char I2C_rd1[64]; // 生データ |
yusuke_kyo | 3:6a932d0aac7d | 132 | short datr1[16]; // 16点 温度データ(10倍整数) |
yusuke_kyo | 3:6a932d0aac7d | 133 | short PTAT1; // センサ内部PTAT温度データ(10倍整数) |
yusuke_kyo | 3:6a932d0aac7d | 134 | double dt1[16]; // 16点 温度データ |
yusuke_kyo | 3:6a932d0aac7d | 135 | double dt1_temp[16]; |
yusuke_kyo | 3:6a932d0aac7d | 136 | short d_PTAT1; // センサ内部PTAT温度データ |
yusuke_kyo | 3:6a932d0aac7d | 137 | |
yusuke_kyo | 3:6a932d0aac7d | 138 | char I2C_rd2[64]; // 生データ |
yusuke_kyo | 3:6a932d0aac7d | 139 | short datr2[16]; // 16点 温度データ(10倍整数) |
yusuke_kyo | 3:6a932d0aac7d | 140 | short PTAT2; // センサ内部PTAT温度データ(10倍整数) |
yusuke_kyo | 3:6a932d0aac7d | 141 | double dt2[16]; // 16点 温度データ |
yusuke_kyo | 3:6a932d0aac7d | 142 | double dt2_temp[16]; |
yusuke_kyo | 3:6a932d0aac7d | 143 | short d_PTAT2; // センサ内部PTAT温度データ |
yusuke_kyo | 0:8822acabe470 | 144 | |
yusuke_kyo | 0:8822acabe470 | 145 | void GetThermo(char* data) { |
yusuke_kyo | 3:6a932d0aac7d | 146 | char con[6]; |
yusuke_kyo | 3:6a932d0aac7d | 147 | sprintf(data,""); |
yusuke_kyo | 0:8822acabe470 | 148 | |
yusuke_kyo | 0:8822acabe470 | 149 | /*MEMS1*/ |
yusuke_kyo | 0:8822acabe470 | 150 | int i,j; |
yusuke_kyo | 0:8822acabe470 | 151 | int itemp; |
yusuke_kyo | 0:8822acabe470 | 152 | |
yusuke_kyo | 0:8822acabe470 | 153 | //// measure |
yusuke_kyo | 0:8822acabe470 | 154 | MEMS1.start(); |
yusuke_kyo | 0:8822acabe470 | 155 | MEMS1.write(D6T_addr); |
yusuke_kyo | 0:8822acabe470 | 156 | MEMS1.write(D6T_cmd); |
yusuke_kyo | 0:8822acabe470 | 157 | // Repeated Start condition |
yusuke_kyo | 0:8822acabe470 | 158 | MEMS1.read(D6T_addr,I2C_rd1,35); |
yusuke_kyo | 0:8822acabe470 | 159 | // if(check_PEC(I2C_rd) == -1) continue; // error |
yusuke_kyo | 0:8822acabe470 | 160 | for(i=0,j=0;i<17;i++){ |
yusuke_kyo | 0:8822acabe470 | 161 | itemp = (I2C_rd1[j++] & 0xff); |
yusuke_kyo | 0:8822acabe470 | 162 | itemp += I2C_rd1[j++] * 256; |
yusuke_kyo | 0:8822acabe470 | 163 | if(i == 0) PTAT1 = itemp; |
yusuke_kyo | 0:8822acabe470 | 164 | else datr1[i-1] = itemp; |
yusuke_kyo | 0:8822acabe470 | 165 | } |
yusuke_kyo | 0:8822acabe470 | 166 | for(i=0;i<16;i++){ |
yusuke_kyo | 0:8822acabe470 | 167 | dt1[i] = 0.1 * datr1[i]; |
yusuke_kyo | 0:8822acabe470 | 168 | } |
yusuke_kyo | 0:8822acabe470 | 169 | for(int i=0;i<16;i++){ |
yusuke_kyo | 3:6a932d0aac7d | 170 | if(dt1[i]<50 && dt1[i]>5) { |
yusuke_kyo | 3:6a932d0aac7d | 171 | sprintf(con,"%3.1f ",dt1[i]); |
yusuke_kyo | 3:6a932d0aac7d | 172 | dt1_temp[i]=dt1[i]; |
yusuke_kyo | 3:6a932d0aac7d | 173 | } |
yusuke_kyo | 3:6a932d0aac7d | 174 | else sprintf(con,"%3.1f ",dt1_temp[i]); |
yusuke_kyo | 0:8822acabe470 | 175 | strcat(data,con); |
yusuke_kyo | 0:8822acabe470 | 176 | } |
yusuke_kyo | 2:f0efe1d10f8a | 177 | if(THERMO_DEBUG){ |
yusuke_kyo | 3:6a932d0aac7d | 178 | printf("\nThermal_Sensor 1"); |
yusuke_kyo | 2:f0efe1d10f8a | 179 | for(i=0;i<16;i++){ |
yusuke_kyo | 2:f0efe1d10f8a | 180 | if(i%4==0) printf("\n"); |
yusuke_kyo | 2:f0efe1d10f8a | 181 | printf("%3.1f ",dt1[i]); |
yusuke_kyo | 2:f0efe1d10f8a | 182 | } printf("\n"); |
yusuke_kyo | 2:f0efe1d10f8a | 183 | } |
yusuke_kyo | 0:8822acabe470 | 184 | d_PTAT1 = 0.1 * PTAT1; |
yusuke_kyo | 0:8822acabe470 | 185 | wait(0.1); |
yusuke_kyo | 0:8822acabe470 | 186 | /*MEMS1*/ |
yusuke_kyo | 0:8822acabe470 | 187 | |
yusuke_kyo | 3:6a932d0aac7d | 188 | /*MEMS2*/ |
yusuke_kyo | 0:8822acabe470 | 189 | //// measure |
yusuke_kyo | 0:8822acabe470 | 190 | MEMS2.start(); |
yusuke_kyo | 0:8822acabe470 | 191 | MEMS2.write(D6T_addr); |
yusuke_kyo | 0:8822acabe470 | 192 | MEMS2.write(D6T_cmd); |
yusuke_kyo | 0:8822acabe470 | 193 | // Repeated Start condition |
yusuke_kyo | 0:8822acabe470 | 194 | MEMS2.read(D6T_addr,I2C_rd2,35); |
yusuke_kyo | 0:8822acabe470 | 195 | // if(check_PEC(I2C_rd) == -1) continue; // error |
yusuke_kyo | 0:8822acabe470 | 196 | for(i=0,j=0;i<17;i++){ |
yusuke_kyo | 0:8822acabe470 | 197 | itemp = (I2C_rd2[j++] & 0xff); |
yusuke_kyo | 0:8822acabe470 | 198 | itemp += I2C_rd2[j++] * 256; |
yusuke_kyo | 0:8822acabe470 | 199 | if(i == 0) PTAT2 = itemp; |
yusuke_kyo | 0:8822acabe470 | 200 | else datr2[i-1] = itemp; |
yusuke_kyo | 0:8822acabe470 | 201 | } |
yusuke_kyo | 0:8822acabe470 | 202 | for(i=0;i<16;i++){ |
yusuke_kyo | 0:8822acabe470 | 203 | dt2[i] = 0.1 * datr2[i]; |
yusuke_kyo | 0:8822acabe470 | 204 | } |
yusuke_kyo | 0:8822acabe470 | 205 | for(int i=0;i<16;i++){ |
yusuke_kyo | 3:6a932d0aac7d | 206 | if(dt1[i]<50 && dt1[i]>5) { |
yusuke_kyo | 3:6a932d0aac7d | 207 | sprintf(con,"%3.1f ",dt2[i]); |
yusuke_kyo | 3:6a932d0aac7d | 208 | dt2_temp[i]=dt2[i]; |
yusuke_kyo | 3:6a932d0aac7d | 209 | } |
yusuke_kyo | 3:6a932d0aac7d | 210 | else sprintf(con,"%3.1f ",dt2_temp[i]); |
yusuke_kyo | 0:8822acabe470 | 211 | strcat(data,con); |
yusuke_kyo | 0:8822acabe470 | 212 | } |
yusuke_kyo | 2:f0efe1d10f8a | 213 | if(THERMO_DEBUG){ |
yusuke_kyo | 3:6a932d0aac7d | 214 | printf("\nThermal_Sensor 2"); |
yusuke_kyo | 2:f0efe1d10f8a | 215 | for(i=0;i<16;i++){ |
yusuke_kyo | 2:f0efe1d10f8a | 216 | if(i%4==0) printf("\n"); |
yusuke_kyo | 2:f0efe1d10f8a | 217 | printf("%3.1f ",dt2[i]); |
yusuke_kyo | 2:f0efe1d10f8a | 218 | } printf("\n"); |
yusuke_kyo | 2:f0efe1d10f8a | 219 | } |
yusuke_kyo | 0:8822acabe470 | 220 | d_PTAT2 = 0.1 * PTAT2; |
yusuke_kyo | 0:8822acabe470 | 221 | wait(0.1); |
yusuke_kyo | 0:8822acabe470 | 222 | /*MEMS2*/ |
yusuke_kyo | 0:8822acabe470 | 223 | } |
yusuke_kyo | 0:8822acabe470 | 224 | /*--Thermal_Sensor:end------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 225 | |
yusuke_kyo | 0:8822acabe470 | 226 | /*--CO2_Sensor:begin--------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 227 | /*CO2センサモジュール:A051020-AQ6B-01*/ |
yusuke_kyo | 0:8822acabe470 | 228 | /*データシート:http://www.fisinc.co.jp/common/pdf/A051020-AQ6.pdf*/ |
yusuke_kyo | 0:8822acabe470 | 229 | /*参考 外気:396.0[ppm](2013年) 呼気:13,200[ppm] ※このセンサで測れるのは3000[ppm]まで*/ |
yusuke_kyo | 0:8822acabe470 | 230 | #include "mbed.h" |
yusuke_kyo | 0:8822acabe470 | 231 | |
yusuke_kyo | 0:8822acabe470 | 232 | AnalogIn ain(p20); |
yusuke_kyo | 0:8822acabe470 | 233 | |
yusuke_kyo | 3:6a932d0aac7d | 234 | #define CO2_DEBUG 1 |
yusuke_kyo | 0:8822acabe470 | 235 | |
yusuke_kyo | 0:8822acabe470 | 236 | float GetCO2() { |
yusuke_kyo | 0:8822acabe470 | 237 | float v; //生データ:電圧 |
yusuke_kyo | 0:8822acabe470 | 238 | float sensor_v,CO2; |
yusuke_kyo | 0:8822acabe470 | 239 | |
yusuke_kyo | 0:8822acabe470 | 240 | v = ain.read()*3.3; |
yusuke_kyo | 0:8822acabe470 | 241 | sensor_v = v * 5.0/3.3; //電圧レベルを合わせる |
yusuke_kyo | 0:8822acabe470 | 242 | CO2 = sensor_v * 1000 + 400; //データシートより |
yusuke_kyo | 0:8822acabe470 | 243 | |
yusuke_kyo | 0:8822acabe470 | 244 | if(CO2_DEBUG) printf("\nCO2:%4.1f\n",CO2); |
yusuke_kyo | 0:8822acabe470 | 245 | |
yusuke_kyo | 0:8822acabe470 | 246 | return(CO2); |
yusuke_kyo | 0:8822acabe470 | 247 | } |
yusuke_kyo | 0:8822acabe470 | 248 | /*--CO2_Sensor:end----------------------------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 249 | |
yusuke_kyo | 0:8822acabe470 | 250 | |
yusuke_kyo | 0:8822acabe470 | 251 | /*--------------- |
yusuke_kyo | 0:8822acabe470 | 252 | MAIN ROOP |
yusuke_kyo | 0:8822acabe470 | 253 | ----------------*/ |
yusuke_kyo | 0:8822acabe470 | 254 | |
yusuke_kyo | 0:8822acabe470 | 255 | int main() { |
yusuke_kyo | 3:6a932d0aac7d | 256 | char Dyna_data[50]; |
yusuke_kyo | 3:6a932d0aac7d | 257 | char Thermo_data[200]; |
yusuke_kyo | 0:8822acabe470 | 258 | float CO2_data; |
yusuke_kyo | 0:8822acabe470 | 259 | |
yusuke_kyo | 0:8822acabe470 | 260 | Dyna_init(); |
yusuke_kyo | 0:8822acabe470 | 261 | |
yusuke_kyo | 3:6a932d0aac7d | 262 | char Send_data[250]; |
yusuke_kyo | 0:8822acabe470 | 263 | int Read_data; |
yusuke_kyo | 0:8822acabe470 | 264 | int Joy_mode, linear_mode, pitch_mode, yaw_mode; |
yusuke_kyo | 0:8822acabe470 | 265 | |
yusuke_kyo | 0:8822acabe470 | 266 | while(1) { |
yusuke_kyo | 0:8822acabe470 | 267 | |
yusuke_kyo | 0:8822acabe470 | 268 | Read_data=pc.getc(); |
yusuke_kyo | 0:8822acabe470 | 269 | wait_ms(1); |
yusuke_kyo | 2:f0efe1d10f8a | 270 | Joy_mode = Read_data & 0xc0; Joy_mode = Joy_mode >> 6; //ジョイスティックのモード判定 |
yusuke_kyo | 0:8822acabe470 | 271 | |
yusuke_kyo | 0:8822acabe470 | 272 | switch(Joy_mode){ |
yusuke_kyo | 0:8822acabe470 | 273 | case 0: //通常モード |
yusuke_kyo | 0:8822acabe470 | 274 | myled1=0; myled2=0; myled3=0; myled4=0; |
yusuke_kyo | 0:8822acabe470 | 275 | /*--Dynamixel:begin---------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 276 | //Dynamixelへの命令を判定 |
yusuke_kyo | 2:f0efe1d10f8a | 277 | linear_mode = Read_data & 0x30; linear_mode = linear_mode >> 4; |
yusuke_kyo | 2:f0efe1d10f8a | 278 | pitch_mode = Read_data & 0x0c; pitch_mode = pitch_mode >> 2; |
yusuke_kyo | 2:f0efe1d10f8a | 279 | yaw_mode = Read_data & 0x03; |
yusuke_kyo | 0:8822acabe470 | 280 | |
yusuke_kyo | 0:8822acabe470 | 281 | //現在の角度・電圧・電流を取得 |
yusuke_kyo | 0:8822acabe470 | 282 | myled1=1; |
yusuke_kyo | 0:8822acabe470 | 283 | Dyna_GetData(Dyna_data); |
yusuke_kyo | 0:8822acabe470 | 284 | myled1=0; |
yusuke_kyo | 0:8822acabe470 | 285 | |
yusuke_kyo | 0:8822acabe470 | 286 | //目標角度を変更 |
yusuke_kyo | 0:8822acabe470 | 287 | myled2=1; |
yusuke_kyo | 0:8822acabe470 | 288 | Dyna_SetGoal(linear_mode, pitch_mode, yaw_mode); |
yusuke_kyo | 0:8822acabe470 | 289 | myled2=0; |
yusuke_kyo | 0:8822acabe470 | 290 | /*--Dynamixel:end------------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 291 | |
yusuke_kyo | 0:8822acabe470 | 292 | /*--Thermal_Sensor:begin-----------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 293 | //値を取得 |
yusuke_kyo | 0:8822acabe470 | 294 | myled3=1; |
yusuke_kyo | 0:8822acabe470 | 295 | GetThermo(Thermo_data); |
yusuke_kyo | 0:8822acabe470 | 296 | /*--Thermal_Sensor:end-------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 297 | |
yusuke_kyo | 0:8822acabe470 | 298 | /*--CO2_Sensor:begin---------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 299 | //値を取得 |
yusuke_kyo | 0:8822acabe470 | 300 | CO2_data=GetCO2(); |
yusuke_kyo | 0:8822acabe470 | 301 | myled3=0; |
yusuke_kyo | 0:8822acabe470 | 302 | /*--CO2_Sensor:end-----------------------------------------------------------------*/ |
yusuke_kyo | 0:8822acabe470 | 303 | |
yusuke_kyo | 0:8822acabe470 | 304 | //値を送信 |
yusuke_kyo | 0:8822acabe470 | 305 | myled4=1; |
yusuke_kyo | 0:8822acabe470 | 306 | sprintf(Send_data,"%s%s%f",Dyna_data,Thermo_data,CO2_data); |
yusuke_kyo | 3:6a932d0aac7d | 307 | printf("Send_data : %s\n",Send_data); |
yusuke_kyo | 0:8822acabe470 | 308 | myled4=0; |
yusuke_kyo | 0:8822acabe470 | 309 | break; |
yusuke_kyo | 0:8822acabe470 | 310 | |
yusuke_kyo | 0:8822acabe470 | 311 | case 1: //ホームポジション |
yusuke_kyo | 0:8822acabe470 | 312 | myled1=1; myled2=0; myled3=0; myled4=1; Dyna_home_position(); break; |
yusuke_kyo | 0:8822acabe470 | 313 | |
yusuke_kyo | 0:8822acabe470 | 314 | case 2: //リセット |
yusuke_kyo | 0:8822acabe470 | 315 | myled1=0; myled2=1; myled3=1; myled4=0; Dyna_reset(); break; |
yusuke_kyo | 0:8822acabe470 | 316 | |
yusuke_kyo | 0:8822acabe470 | 317 | case 3: //終了 |
yusuke_kyo | 0:8822acabe470 | 318 | myled1=1; myled2=1; myled3=1; myled4=1; Dyna_end(); break; |
yusuke_kyo | 0:8822acabe470 | 319 | } |
yusuke_kyo | 0:8822acabe470 | 320 | } |
yusuke_kyo | 0:8822acabe470 | 321 | } |