YOZAKURA ARM program, usb serial

Dependencies:   Dynamixel SerialHalfDuplex mbed

Committer:
yusuke_kyo
Date:
Mon Apr 27 04:21:44 2015 +0000
Revision:
7:58eb1e1e9143
Parent:
6:6d9dac9ff798
wait

Who changed what in which revision?

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