add pcon f and b

Dependencies:   mbed HCSR04

Committer:
Tomo1213
Date:
Sun Dec 19 18:48:16 2021 +0000
Revision:
7:df29c4de6522
Parent:
6:07534de7cdb4
Child:
8:c9a5ef6f003f
hitoganoruno dekita

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Tomo1213 5:a7c3f446a1f1 1 //2021/12/20更新
ngokystk 0:b4b94eb28093 2 //YUKA本番機用プログラム
ngokystk 0:b4b94eb28093 3 //入力切替確認済み
ngokystk 0:b4b94eb28093 4 //一定時間の入力なしで動作切替
ngokystk 0:b4b94eb28093 5 //ジグザグ動作実装前
ngokystk 0:b4b94eb28093 6 //エンコーダ読み取りによる入力
ngokystk 0:b4b94eb28093 7 //加減速度調整パラメータ実装
ngokystk 0:b4b94eb28093 8 //PID制御による機体角度補正_
Tomo1213 3:c39c14cfc811 9 //aoki
Tomo1213 1:b2bd1511307e 10
ngokystk 0:b4b94eb28093 11 #include "mbed.h"
ngokystk 0:b4b94eb28093 12 #include "hcsr04.h"
ngokystk 0:b4b94eb28093 13
Tomo1213 1:b2bd1511307e 14 #define ACC_B 1000
Tomo1213 1:b2bd1511307e 15 #define DEC_B 700
Tomo1213 1:b2bd1511307e 16 #define ACC_C 1000
Tomo1213 1:b2bd1511307e 17 #define DEC_C 1000
ngokystk 0:b4b94eb28093 18
Tomo1213 1:b2bd1511307e 19 #define KICK 2000
Tomo1213 1:b2bd1511307e 20
Tomo1213 7:df29c4de6522 21 #define WALL 45
Tomo1213 3:c39c14cfc811 22
Tomo1213 3:c39c14cfc811 23
ngokystk 0:b4b94eb28093 24 DigitalOut led1(LED1);
ngokystk 0:b4b94eb28093 25 DigitalOut led2(LED2);
ngokystk 0:b4b94eb28093 26 DigitalOut led3(LED3);
ngokystk 0:b4b94eb28093 27 DigitalOut led4(LED4);
Tomo1213 1:b2bd1511307e 28
ngokystk 0:b4b94eb28093 29 Timer t;
ngokystk 0:b4b94eb28093 30 double Time = 0;
ngokystk 0:b4b94eb28093 31 #define Standby_Time 10
ngokystk 0:b4b94eb28093 32 Serial pc(USBTX, USBRX);
ngokystk 0:b4b94eb28093 33 char Serialdata;
ngokystk 0:b4b94eb28093 34 BusOut myled(LED1, LED2, LED3, LED4);
Tomo1213 1:b2bd1511307e 35
ngokystk 0:b4b94eb28093 36 //HCSR04 u1(p13, p14), u2(p11, p12), u3(p23, p24), u4(p25, p26); // Trigger(DO), Echo(PWMIN); LPC1768
ngokystk 0:b4b94eb28093 37 HCSR04 u1(PA_0, PA_1),u2(PA_5, PA_6),u3(PB_0, PA_10); // Trigger(DO), Echo(PWMIN); f303k8
Tomo1213 1:b2bd1511307e 38
ngokystk 0:b4b94eb28093 39 CANMessage canmsgTx;
ngokystk 0:b4b94eb28093 40 CANMessage canmsgRx;
ngokystk 0:b4b94eb28093 41 //CAN canPort(p30, p29); //CAN name(PinName rd, PinName td) LPC1768
ngokystk 0:b4b94eb28093 42 CAN canPort(PA_11, PA_12); //CAN name(PinName rd, PinName td) F303k8
Tomo1213 1:b2bd1511307e 43
ngokystk 0:b4b94eb28093 44 //プロトタイプ宣言
ngokystk 0:b4b94eb28093 45 //------------------send関数-------------------
ngokystk 0:b4b94eb28093 46 //mode Setting
ngokystk 0:b4b94eb28093 47 void sendOPModeT(int); //Operating Mode
ngokystk 0:b4b94eb28093 48 void sendOPModeV(int); //Operating Mode
ngokystk 0:b4b94eb28093 49 //Control Word
ngokystk 0:b4b94eb28093 50 void sendCtrlRS(int); //Reset
ngokystk 0:b4b94eb28093 51 void sendCtrlSD(int); //Shutdown
ngokystk 0:b4b94eb28093 52 void sendCtrlEN(int); //Switch on & Enable
ngokystk 0:b4b94eb28093 53 void sendCtrlQS(int); //Quick Stop
ngokystk 0:b4b94eb28093 54 void sendCtrlHL(int); //Halt
ngokystk 0:b4b94eb28093 55 //Velocity Setting
ngokystk 0:b4b94eb28093 56 void sendTgtVel(int,int); //Target Velocity
ngokystk 0:b4b94eb28093 57 //Torque Setting
ngokystk 0:b4b94eb28093 58 void sendTgtTrq(int,int); //Target Torque
ngokystk 0:b4b94eb28093 59 //Acceleration Setting
ngokystk 0:b4b94eb28093 60 void sendProAcc(int,int); //Plof Acceleration
ngokystk 0:b4b94eb28093 61 void sendProDec(int,int); //Plof Deceleration
ngokystk 0:b4b94eb28093 62 //------------------read関数-------------------
ngokystk 0:b4b94eb28093 63 void readActVel(int); //Actual Velocity
ngokystk 0:b4b94eb28093 64 void readActPos(int); //Actual Position
ngokystk 0:b4b94eb28093 65 //-------------------その他--------------------
ngokystk 0:b4b94eb28093 66 void printCANTX(void); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 67 void printCANRX(void); //CAN受信データをPCに表示
ngokystk 0:b4b94eb28093 68 void CANdataRX(void); //CAN受信処理
ngokystk 0:b4b94eb28093 69 void SerialRX(void); //Serial受信処理
Tomo1213 1:b2bd1511307e 70 //---------------------------------------------
Tomo1213 1:b2bd1511307e 71 void set_ACC(int);
Tomo1213 1:b2bd1511307e 72 void set_DEC(int);
Tomo1213 1:b2bd1511307e 73 void set_MODE_V(void);
Tomo1213 1:b2bd1511307e 74 void set_MODE_T(void);
ngokystk 0:b4b94eb28093 75
Tomo1213 5:a7c3f446a1f1 76 void vel_stop(void);
Tomo1213 5:a7c3f446a1f1 77 void vel_forward(int);
Tomo1213 5:a7c3f446a1f1 78 void vel_backward(int);
Tomo1213 7:df29c4de6522 79 void vel_right(int);
Tomo1213 7:df29c4de6522 80 void vel_left(int);
Tomo1213 5:a7c3f446a1f1 81
Tomo1213 7:df29c4de6522 82 //unsigned int get_cm_n(HCSR04, unsigned int);
Tomo1213 7:df29c4de6522 83 //USE -> unsigned int dist_UnitA = get_cm_n(u2, 5);
Tomo1213 7:df29c4de6522 84 unsigned int get_cm_n(HCSR04 &echo_unit,int echo_n){
Tomo1213 7:df29c4de6522 85 unsigned int sampled_dist=0;
Tomo1213 7:df29c4de6522 86 for (int iter_n = 0; iter_n <echo_n; iter_n++){
Tomo1213 7:df29c4de6522 87 echo_unit.start();
Tomo1213 7:df29c4de6522 88 sampled_dist += echo_unit.get_dist_cm();
Tomo1213 7:df29c4de6522 89 }
Tomo1213 7:df29c4de6522 90 return (sampled_dist / echo_n);
Tomo1213 7:df29c4de6522 91 }
Tomo1213 5:a7c3f446a1f1 92
ngokystk 0:b4b94eb28093 93 int nodeall=4;
Tomo1213 1:b2bd1511307e 94
ngokystk 0:b4b94eb28093 95 int main(){
ngokystk 0:b4b94eb28093 96 //Serial
ngokystk 0:b4b94eb28093 97 pc.attach(SerialRX);
ngokystk 0:b4b94eb28093 98 //pc.baud(115200);
ngokystk 0:b4b94eb28093 99
ngokystk 0:b4b94eb28093 100 //CAN
ngokystk 0:b4b94eb28093 101 canPort.frequency(1000000); //Bit Rate:1MHz
ngokystk 0:b4b94eb28093 102 canPort.attach(CANdataRX,CAN::RxIrq);
ngokystk 0:b4b94eb28093 103 int node1 = 1; //CAN node Setting
ngokystk 0:b4b94eb28093 104 int node2 = 2;
ngokystk 0:b4b94eb28093 105 int node3 = 3;
ngokystk 0:b4b94eb28093 106 int node4 = 4;
ngokystk 0:b4b94eb28093 107
Tomo1213 3:c39c14cfc811 108 //モータ回転数
Tomo1213 7:df29c4de6522 109 int rpm = 400;
Tomo1213 3:c39c14cfc811 110
ngokystk 0:b4b94eb28093 111 //エンコーダ関係
ngokystk 0:b4b94eb28093 112 int ActPos = 0;
ngokystk 0:b4b94eb28093 113 int Init_Pos = 0;
ngokystk 0:b4b94eb28093 114
ngokystk 0:b4b94eb28093 115 //超音波センサ関係パラメータ
Tomo1213 5:a7c3f446a1f1 116 int dist1,dist2,dist3,dist4;
ngokystk 0:b4b94eb28093 117
ngokystk 0:b4b94eb28093 118 //PID制御関係
ngokystk 0:b4b94eb28093 119 //角度調整パラメータ
Tomo1213 5:a7c3f446a1f1 120
Tomo1213 5:a7c3f446a1f1 121
ngokystk 0:b4b94eb28093 122 #define DELTA_T1 0.1
ngokystk 0:b4b94eb28093 123 #define target_val1 0
ngokystk 0:b4b94eb28093 124 #define Kp1 3
ngokystk 0:b4b94eb28093 125 #define Ki1 0
ngokystk 0:b4b94eb28093 126 #define Kd1 0
Tomo1213 1:b2bd1511307e 127
ngokystk 0:b4b94eb28093 128 pc.printf("YUKA PROGRAM START\r\n");
ngokystk 0:b4b94eb28093 129 wait(0.1);
ngokystk 0:b4b94eb28093 130 //-------------起動時に必ず送信---------------
ngokystk 0:b4b94eb28093 131 //オペレーティングモードを送信
Tomo1213 3:c39c14cfc811 132 sendOPModeT(node1);
Tomo1213 3:c39c14cfc811 133 sendOPModeT(node2);
Tomo1213 3:c39c14cfc811 134 sendOPModeT(node3);
Tomo1213 3:c39c14cfc811 135 sendOPModeT(node4);
Tomo1213 3:c39c14cfc811 136
ngokystk 0:b4b94eb28093 137 //Shutdown,Enableコマンド送信|リセット
ngokystk 0:b4b94eb28093 138 sendCtrlSD(node1);
ngokystk 0:b4b94eb28093 139 sendCtrlSD(node2);
ngokystk 0:b4b94eb28093 140 sendCtrlSD(node3);
ngokystk 0:b4b94eb28093 141 sendCtrlSD(node4);
Tomo1213 1:b2bd1511307e 142
ngokystk 0:b4b94eb28093 143 sendCtrlEN(node1);
ngokystk 0:b4b94eb28093 144 sendCtrlEN(node2);
ngokystk 0:b4b94eb28093 145 sendCtrlEN(node3);
ngokystk 0:b4b94eb28093 146 sendCtrlEN(node4);
ngokystk 0:b4b94eb28093 147
ngokystk 0:b4b94eb28093 148 //初期加減速度
Tomo1213 3:c39c14cfc811 149 int Acc = 2000;
Tomo1213 3:c39c14cfc811 150 int Dec = 2000;
Tomo1213 3:c39c14cfc811 151
Tomo1213 3:c39c14cfc811 152 sendProAcc(1,Acc);
Tomo1213 3:c39c14cfc811 153 sendProAcc(2,Acc);
Tomo1213 3:c39c14cfc811 154 sendProAcc(3,Acc);
Tomo1213 3:c39c14cfc811 155 sendProAcc(4,Acc);
Tomo1213 3:c39c14cfc811 156
Tomo1213 3:c39c14cfc811 157 sendProDec(1,Dec);
Tomo1213 3:c39c14cfc811 158 sendProDec(2,Dec);
Tomo1213 3:c39c14cfc811 159 sendProDec(3,Dec);
Tomo1213 3:c39c14cfc811 160 sendProDec(4,Dec);
Tomo1213 3:c39c14cfc811 161
ngokystk 0:b4b94eb28093 162 //トルク設定
ngokystk 0:b4b94eb28093 163 int trq = 100; //torque Setting[mA]
ngokystk 0:b4b94eb28093 164
ngokystk 0:b4b94eb28093 165 sendTgtTrq(1,trq);
ngokystk 0:b4b94eb28093 166 sendTgtTrq(2,trq);
ngokystk 0:b4b94eb28093 167 sendTgtTrq(3,trq);
ngokystk 0:b4b94eb28093 168 sendTgtTrq(4,trq);
Tomo1213 1:b2bd1511307e 169
Tomo1213 5:a7c3f446a1f1 170 int state_1 = 0;
Tomo1213 5:a7c3f446a1f1 171
Tomo1213 7:df29c4de6522 172 ActPos = 0;
Tomo1213 7:df29c4de6522 173 Init_Pos = 0;
Tomo1213 7:df29c4de6522 174 dist1 = 0;
Tomo1213 7:df29c4de6522 175 readActPos(1);
Tomo1213 7:df29c4de6522 176 ActPos=canmsgRx.data[4]+canmsgRx.data[5]*256+canmsgRx.data[6]*65536;
Tomo1213 7:df29c4de6522 177 if(ActPos > 8388608){
Tomo1213 7:df29c4de6522 178 ActPos -= 0x1000000;//16進数でのマイナス処理 16^7 = 16,777,216 = 0x1000000
Tomo1213 7:df29c4de6522 179 }
Tomo1213 7:df29c4de6522 180 Init_Pos = ActPos;//起動時の角度を保存
Tomo1213 7:df29c4de6522 181 t.reset();
Tomo1213 7:df29c4de6522 182 t.start();
Tomo1213 7:df29c4de6522 183
Tomo1213 7:df29c4de6522 184 //set_MODE_T();
Tomo1213 7:df29c4de6522 185
Tomo1213 7:df29c4de6522 186 printf("\nstart\r\n");
Tomo1213 7:df29c4de6522 187
Tomo1213 7:df29c4de6522 188 while(1){
Tomo1213 7:df29c4de6522 189
Tomo1213 7:df29c4de6522 190 Time = t.read();
Tomo1213 7:df29c4de6522 191
Tomo1213 1:b2bd1511307e 192 readActPos(1);
Tomo1213 1:b2bd1511307e 193 ActPos=canmsgRx.data[4]+canmsgRx.data[5]*256+canmsgRx.data[6]*65536;
Tomo1213 1:b2bd1511307e 194 if(ActPos > 8388608){
Tomo1213 1:b2bd1511307e 195 ActPos -= 0x1000000;//16進数でのマイナス処理 16^7 = 16,777,216 = 0x1000000
Tomo1213 7:df29c4de6522 196 //printf("check\r\n");
ngokystk 0:b4b94eb28093 197 }
Tomo1213 7:df29c4de6522 198 //u1.start();
Tomo1213 7:df29c4de6522 199 //u2.start();
Tomo1213 5:a7c3f446a1f1 200
Tomo1213 7:df29c4de6522 201 //dist1 = u1.get_dist_cm();
Tomo1213 7:df29c4de6522 202 //dist2 = u2.get_dist_cm();
Tomo1213 7:df29c4de6522 203
Tomo1213 7:df29c4de6522 204 dist1 = get_cm_n(u1, 5);
Tomo1213 7:df29c4de6522 205 dist2 = get_cm_n(u2, 5);
Tomo1213 7:df29c4de6522 206 dist3 = get_cm_n(u3, 5);
Tomo1213 5:a7c3f446a1f1 207
Tomo1213 7:df29c4de6522 208 //printf("dsit1 %d\r\n",dist1);
Tomo1213 7:df29c4de6522 209 printf("%d\r\n",state_1);
Tomo1213 7:df29c4de6522 210 /*--------------------------*/
Tomo1213 7:df29c4de6522 211 //前方向に入力があった時
Tomo1213 7:df29c4de6522 212 if(state_1 == 0){//入力判断フェーズ
Tomo1213 7:df29c4de6522 213 if(ActPos < (Init_Pos - KICK)){
Tomo1213 7:df29c4de6522 214 state_1 = 1;
Tomo1213 7:df29c4de6522 215 }else if(ActPos > (Init_Pos + KICK)){
Tomo1213 7:df29c4de6522 216 state_1 = 11;
Tomo1213 7:df29c4de6522 217 }else{
Tomo1213 7:df29c4de6522 218 set_MODE_T();
Tomo1213 7:df29c4de6522 219 }
Tomo1213 7:df29c4de6522 220 }else if(state_1 == 1){//前進→壁検出フェーズ
Tomo1213 7:df29c4de6522 221 if(dist1 < WALL && dist1 >= 25){
Tomo1213 7:df29c4de6522 222 state_1 = 2;
Tomo1213 7:df29c4de6522 223 }else{
Tomo1213 7:df29c4de6522 224 set_ACC(ACC_B);//加速度設定
Tomo1213 7:df29c4de6522 225 set_DEC(ACC_C);//減速度設定
Tomo1213 7:df29c4de6522 226 set_MODE_V();//速度制御モード送信
Tomo1213 7:df29c4de6522 227 vel_forward(rpm);//前進速度指令
Tomo1213 7:df29c4de6522 228 }
Tomo1213 7:df29c4de6522 229 }else if(state_1 == 2){//前進からの帰還フェーズ
Tomo1213 7:df29c4de6522 230 if(ActPos > -3000){
Tomo1213 7:df29c4de6522 231 vel_stop();
Tomo1213 7:df29c4de6522 232 state_1 = 0;
Tomo1213 7:df29c4de6522 233 wait(1.0);
Tomo1213 7:df29c4de6522 234 //break;
Tomo1213 7:df29c4de6522 235 }else{
Tomo1213 7:df29c4de6522 236 vel_backward(rpm);
Tomo1213 7:df29c4de6522 237 }
Tomo1213 7:df29c4de6522 238 }else if(state_1 == 11){//右進→壁検出フェーズ
Tomo1213 7:df29c4de6522 239 if(dist3 < WALL && dist3 >= 25){
Tomo1213 7:df29c4de6522 240 state_1 = 12;
Tomo1213 7:df29c4de6522 241 }else{
Tomo1213 7:df29c4de6522 242 set_ACC(ACC_B);//加速度設定
Tomo1213 7:df29c4de6522 243 set_DEC(ACC_C);//減速度設定
Tomo1213 7:df29c4de6522 244 set_MODE_V();//速度制御モード送信
Tomo1213 7:df29c4de6522 245 vel_right(rpm);//前進速度指令
Tomo1213 7:df29c4de6522 246 }
Tomo1213 7:df29c4de6522 247 }else if(state_1 == 12){//右進からの帰還フェーズ
Tomo1213 7:df29c4de6522 248 if(ActPos < 3000){
Tomo1213 7:df29c4de6522 249 vel_stop();
Tomo1213 7:df29c4de6522 250 state_1 = 0;
Tomo1213 7:df29c4de6522 251 wait(1.0);
Tomo1213 7:df29c4de6522 252 //break;
Tomo1213 7:df29c4de6522 253 }else{
Tomo1213 7:df29c4de6522 254 vel_left(rpm);
Tomo1213 7:df29c4de6522 255 }
Tomo1213 7:df29c4de6522 256 }
Tomo1213 7:df29c4de6522 257 }
Tomo1213 7:df29c4de6522 258
Tomo1213 7:df29c4de6522 259 }
Tomo1213 7:df29c4de6522 260
Tomo1213 7:df29c4de6522 261 void vel_right(int rpm){
Tomo1213 7:df29c4de6522 262 sendTgtVel(1,rpm);
Tomo1213 7:df29c4de6522 263 sendTgtVel(2,rpm*(-1));
Tomo1213 7:df29c4de6522 264 sendTgtVel(3,rpm*(-1));
Tomo1213 7:df29c4de6522 265 sendTgtVel(4,rpm);
Tomo1213 7:df29c4de6522 266 for(int i=1;i<= 4;i++){
Tomo1213 7:df29c4de6522 267 sendCtrlEN(i);
Tomo1213 7:df29c4de6522 268 }
Tomo1213 7:df29c4de6522 269 }
Tomo1213 7:df29c4de6522 270
Tomo1213 7:df29c4de6522 271 void vel_left(int rpm){
Tomo1213 7:df29c4de6522 272 sendTgtVel(1,rpm*(-1));
Tomo1213 7:df29c4de6522 273 sendTgtVel(2,rpm);
Tomo1213 7:df29c4de6522 274 sendTgtVel(3,rpm);
Tomo1213 7:df29c4de6522 275 sendTgtVel(4,rpm*(-1));
Tomo1213 7:df29c4de6522 276 for(int i=1;i<= 4;i++){
Tomo1213 7:df29c4de6522 277 sendCtrlEN(i);
Tomo1213 5:a7c3f446a1f1 278 }
Tomo1213 5:a7c3f446a1f1 279 }
Tomo1213 5:a7c3f446a1f1 280
Tomo1213 5:a7c3f446a1f1 281 void vel_stop(){
Tomo1213 5:a7c3f446a1f1 282 //速度を指定
Tomo1213 5:a7c3f446a1f1 283 sendTgtVel(1,0);
Tomo1213 5:a7c3f446a1f1 284 sendTgtVel(2,0);
Tomo1213 5:a7c3f446a1f1 285 sendTgtVel(3,0);
Tomo1213 5:a7c3f446a1f1 286 sendTgtVel(4,0);
Tomo1213 5:a7c3f446a1f1 287 //指令値を送信
Tomo1213 5:a7c3f446a1f1 288 for(int i=1;i<= 4;i++){
Tomo1213 5:a7c3f446a1f1 289 sendCtrlEN(i);
Tomo1213 5:a7c3f446a1f1 290 }
Tomo1213 5:a7c3f446a1f1 291 }
ngokystk 0:b4b94eb28093 292
Tomo1213 5:a7c3f446a1f1 293 void vel_backward(int rpm){
Tomo1213 5:a7c3f446a1f1 294 //速度を指定
Tomo1213 5:a7c3f446a1f1 295 sendTgtVel(1,rpm);
Tomo1213 5:a7c3f446a1f1 296 sendTgtVel(2,rpm);
Tomo1213 5:a7c3f446a1f1 297 sendTgtVel(3,rpm*(-1));
Tomo1213 5:a7c3f446a1f1 298 sendTgtVel(4,rpm*(-1));
Tomo1213 5:a7c3f446a1f1 299 //指令値を送信
Tomo1213 5:a7c3f446a1f1 300 for(int i=1;i<= 4;i++){
Tomo1213 5:a7c3f446a1f1 301 sendCtrlEN(i);
Tomo1213 5:a7c3f446a1f1 302 }
Tomo1213 5:a7c3f446a1f1 303 }
Tomo1213 5:a7c3f446a1f1 304
Tomo1213 5:a7c3f446a1f1 305 void vel_forward(int rpm){
Tomo1213 5:a7c3f446a1f1 306 //速度を指定
Tomo1213 5:a7c3f446a1f1 307 sendTgtVel(1,rpm*(-1));
Tomo1213 5:a7c3f446a1f1 308 sendTgtVel(2,rpm*(-1));
Tomo1213 5:a7c3f446a1f1 309 sendTgtVel(3,rpm);
Tomo1213 5:a7c3f446a1f1 310 sendTgtVel(4,rpm);
Tomo1213 5:a7c3f446a1f1 311 //指令値を送信
Tomo1213 5:a7c3f446a1f1 312 for(int i=1;i<= 4;i++){
Tomo1213 5:a7c3f446a1f1 313 sendCtrlEN(i);
Tomo1213 5:a7c3f446a1f1 314 }
Tomo1213 1:b2bd1511307e 315 }
Tomo1213 1:b2bd1511307e 316
Tomo1213 1:b2bd1511307e 317 void set_ACC(int setACC_val){
Tomo1213 1:b2bd1511307e 318 sendProAcc(1,setACC_val);
Tomo1213 1:b2bd1511307e 319 sendProAcc(2,setACC_val);
Tomo1213 1:b2bd1511307e 320 sendProAcc(3,setACC_val);
Tomo1213 1:b2bd1511307e 321 sendProAcc(4,setACC_val);
ngokystk 0:b4b94eb28093 322 }
ngokystk 0:b4b94eb28093 323
Tomo1213 1:b2bd1511307e 324 void set_DEC(int setDEC_val){
Tomo1213 1:b2bd1511307e 325 sendProDec(1,setDEC_val);
Tomo1213 1:b2bd1511307e 326 sendProDec(2,setDEC_val);
Tomo1213 1:b2bd1511307e 327 sendProDec(3,setDEC_val);
Tomo1213 1:b2bd1511307e 328 sendProDec(4,setDEC_val);
Tomo1213 1:b2bd1511307e 329 }
ngokystk 0:b4b94eb28093 330
Tomo1213 1:b2bd1511307e 331 void set_MODE_V(){
Tomo1213 1:b2bd1511307e 332 sendOPModeV(1);
Tomo1213 1:b2bd1511307e 333 sendOPModeV(2);
Tomo1213 1:b2bd1511307e 334 sendOPModeV(3);
Tomo1213 1:b2bd1511307e 335 sendOPModeV(4);
Tomo1213 1:b2bd1511307e 336 }
ngokystk 0:b4b94eb28093 337
Tomo1213 1:b2bd1511307e 338 void set_MODE_T(){
Tomo1213 1:b2bd1511307e 339 sendOPModeT(1);
Tomo1213 1:b2bd1511307e 340 sendOPModeT(2);
Tomo1213 1:b2bd1511307e 341 sendOPModeT(3);
Tomo1213 1:b2bd1511307e 342 sendOPModeT(4);
Tomo1213 1:b2bd1511307e 343 }
ngokystk 0:b4b94eb28093 344
ngokystk 0:b4b94eb28093 345 //0x2F-6060-00-fd-//-//-//
ngokystk 0:b4b94eb28093 346 void sendOPModeT(int nodeID){
ngokystk 0:b4b94eb28093 347 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 348 canmsgTx.len = 5; //Data Length
ngokystk 0:b4b94eb28093 349 canmsgTx.data[0] = 0x2F;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 350 canmsgTx.data[1] = 0x60;//Index LowByte
ngokystk 0:b4b94eb28093 351 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 352 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 353 canmsgTx.data[4] = 0xFD;//data:fd = "current Mode"
ngokystk 0:b4b94eb28093 354 /*
ngokystk 0:b4b94eb28093 355 canmsgTx.data[5] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 356 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 357 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 358 */
ngokystk 0:b4b94eb28093 359 printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 360 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 361 wait_ms(1);
ngokystk 0:b4b94eb28093 362 }
Tomo1213 1:b2bd1511307e 363
Tomo1213 3:c39c14cfc811 364
ngokystk 0:b4b94eb28093 365 //0x2F-6060-00-03-//-//-//
ngokystk 0:b4b94eb28093 366 void sendOPModeV(int nodeID){
ngokystk 0:b4b94eb28093 367 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 368 canmsgTx.len = 5; //Data Length
ngokystk 0:b4b94eb28093 369 canmsgTx.data[0] = 0x2F;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 370 canmsgTx.data[1] = 0x60;//Index LowByte
ngokystk 0:b4b94eb28093 371 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 372 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 373 canmsgTx.data[4] = 0x03;//data:0x03 = "Profile Velocity Mode"
ngokystk 0:b4b94eb28093 374 /*
ngokystk 0:b4b94eb28093 375 canmsgTx.data[5] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 376 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 377 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 378 */
ngokystk 0:b4b94eb28093 379 printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 380 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 381 wait_ms(1);
ngokystk 0:b4b94eb28093 382 }
Tomo1213 1:b2bd1511307e 383
ngokystk 0:b4b94eb28093 384 //0x2B-6040-00-0000-//-//
ngokystk 0:b4b94eb28093 385 void sendCtrlRS(int nodeID){
ngokystk 0:b4b94eb28093 386 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 387 canmsgTx.len = 6; //Data Length
ngokystk 0:b4b94eb28093 388 canmsgTx.data[0] = 0x2B;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 389 canmsgTx.data[1] = 0x40;//Index LowByte
ngokystk 0:b4b94eb28093 390 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 391 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 392 canmsgTx.data[4] = 0x80;//data:0x00"80" = "Controlword(Shutdown)"
ngokystk 0:b4b94eb28093 393 canmsgTx.data[5] = 0x00;//data:0x"00"80
ngokystk 0:b4b94eb28093 394 /*
ngokystk 0:b4b94eb28093 395 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 396 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 397 */
ngokystk 0:b4b94eb28093 398 printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 399 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 400 wait_ms(1);
ngokystk 0:b4b94eb28093 401 }
Tomo1213 1:b2bd1511307e 402
Tomo1213 1:b2bd1511307e 403
ngokystk 0:b4b94eb28093 404 //0x2B-6040-00-0006-//-//
ngokystk 0:b4b94eb28093 405 void sendCtrlSD(int nodeID){
ngokystk 0:b4b94eb28093 406 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 407 canmsgTx.len = 6; //Data Length
ngokystk 0:b4b94eb28093 408 canmsgTx.data[0] = 0x2B;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 409 canmsgTx.data[1] = 0x40;//Index LowByte
ngokystk 0:b4b94eb28093 410 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 411 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 412 canmsgTx.data[4] = 0x06;//data:0x00"06" = "Controlword(Shutdown)"
ngokystk 0:b4b94eb28093 413 canmsgTx.data[5] = 0x00;//data:0x"00"06
ngokystk 0:b4b94eb28093 414 /*
ngokystk 0:b4b94eb28093 415 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 416 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 417 */
ngokystk 0:b4b94eb28093 418 printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 419 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 420 wait_ms(1);
ngokystk 0:b4b94eb28093 421 }
Tomo1213 1:b2bd1511307e 422
ngokystk 0:b4b94eb28093 423 //0x2B-6040-00-000F-//-//
ngokystk 0:b4b94eb28093 424 void sendCtrlEN(int nodeID){
ngokystk 0:b4b94eb28093 425 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 426 canmsgTx.len = 6; //Data Length
ngokystk 0:b4b94eb28093 427 canmsgTx.data[0] = 0x2B;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 428 canmsgTx.data[1] = 0x40;//Index LowByte
ngokystk 0:b4b94eb28093 429 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 430 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 431 canmsgTx.data[4] = 0x0F;//data:0x00"0F" = "Controlword(Enable)"
ngokystk 0:b4b94eb28093 432 canmsgTx.data[5] = 0x00;//data:0x"00"0F
ngokystk 0:b4b94eb28093 433 /*
ngokystk 0:b4b94eb28093 434 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 435 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 436 */
ngokystk 0:b4b94eb28093 437 //printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 438 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 439 wait_ms(1);
ngokystk 0:b4b94eb28093 440 }
Tomo1213 1:b2bd1511307e 441
ngokystk 0:b4b94eb28093 442 //0x2B-6040-00-000B-//-//
ngokystk 0:b4b94eb28093 443 void sendCtrlQS(int nodeID){
ngokystk 0:b4b94eb28093 444 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 445 canmsgTx.len = 6; //Data Length
ngokystk 0:b4b94eb28093 446 canmsgTx.data[0] = 0x2B;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 447 canmsgTx.data[1] = 0x40;//Index LowByte
ngokystk 0:b4b94eb28093 448 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 449 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 450 canmsgTx.data[4] = 0x0B;//data:0x00"0B" = "Quick Stop"
ngokystk 0:b4b94eb28093 451 canmsgTx.data[5] = 0x00;//data:0x"00"0B
ngokystk 0:b4b94eb28093 452 /*
ngokystk 0:b4b94eb28093 453 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 454 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 455 */
ngokystk 0:b4b94eb28093 456 printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 457 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 458 wait_ms(1);
ngokystk 0:b4b94eb28093 459 }
Tomo1213 1:b2bd1511307e 460
ngokystk 0:b4b94eb28093 461 //0x2B-6040-00-010F-//-//
ngokystk 0:b4b94eb28093 462 void sendCtrlHL(int nodeID){
ngokystk 0:b4b94eb28093 463 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 464 canmsgTx.len = 6; //Data Length
ngokystk 0:b4b94eb28093 465 canmsgTx.data[0] = 0x2B;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 466 canmsgTx.data[1] = 0x40;//Index LowByte
ngokystk 0:b4b94eb28093 467 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 468 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 469 canmsgTx.data[4] = 0x0F;//data:0x01"0F" = "Halt"
ngokystk 0:b4b94eb28093 470 canmsgTx.data[5] = 0x01;//data:0x"01"0F
ngokystk 0:b4b94eb28093 471 /*
ngokystk 0:b4b94eb28093 472 canmsgTx.data[6] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 473 canmsgTx.data[7] = 0x00;//data:(user value)
ngokystk 0:b4b94eb28093 474 */
ngokystk 0:b4b94eb28093 475 printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 476 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 477 wait_ms(1);
ngokystk 0:b4b94eb28093 478 }
Tomo1213 1:b2bd1511307e 479
ngokystk 0:b4b94eb28093 480 //0x2B-60FF-00-[user data(4Byte)]
ngokystk 0:b4b94eb28093 481 void sendTgtTrq(int nodeID,int trq){
ngokystk 0:b4b94eb28093 482 //pc.printf("%dmA0x%08x\r\n",trq,trq); //回転数送信データの表示
ngokystk 0:b4b94eb28093 483 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 484 canmsgTx.len = 6; //Data Length
ngokystk 0:b4b94eb28093 485 canmsgTx.data[0] = 0x2B;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 486 canmsgTx.data[1] = 0x30;//Index LowByte 71
ngokystk 0:b4b94eb28093 487 canmsgTx.data[2] = 0x20;//Index HighByte 60
ngokystk 0:b4b94eb28093 488 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 489 //下位から1Byteずつdataに格納
ngokystk 0:b4b94eb28093 490 if(trq<0){
Tomo1213 3:c39c14cfc811 491 trq=0xFFFF+trq+1;
ngokystk 0:b4b94eb28093 492 }
ngokystk 0:b4b94eb28093 493
ngokystk 0:b4b94eb28093 494 //pc.printf("iii%d\r\n",trq);
ngokystk 0:b4b94eb28093 495 //canmsgTx.data[7]=((trq>>24)&0xFF);
ngokystk 0:b4b94eb28093 496 //canmsgTx.data[6]=((trq>>16)&0xFF);
ngokystk 0:b4b94eb28093 497
ngokystk 0:b4b94eb28093 498 canmsgTx.data[5]=((trq>>8)&0xFF);
ngokystk 0:b4b94eb28093 499 canmsgTx.data[4]=((trq>>0)&0xFF);
ngokystk 0:b4b94eb28093 500 //printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 501 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 502 wait_ms(2);
ngokystk 0:b4b94eb28093 503 //send Enable
ngokystk 0:b4b94eb28093 504 //pc.printf("Send Enable Command\r\n");
ngokystk 0:b4b94eb28093 505 //sendCtrlEN(nodeID);
ngokystk 0:b4b94eb28093 506 //wait(0.5);
ngokystk 0:b4b94eb28093 507 }
Tomo1213 1:b2bd1511307e 508
Tomo1213 3:c39c14cfc811 509
Tomo1213 3:c39c14cfc811 510
Tomo1213 3:c39c14cfc811 511
ngokystk 0:b4b94eb28093 512 //0x2B-60FF-00-[user data(4Byte)]
ngokystk 0:b4b94eb28093 513 void sendTgtVel(int nodeID,int rpm){
ngokystk 0:b4b94eb28093 514 //pc.printf("%drpm|0x%08x\r\n",rpm,rpm); //回転数送信データの表示
ngokystk 0:b4b94eb28093 515 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 516 canmsgTx.len = 8; //Data Length
ngokystk 0:b4b94eb28093 517 canmsgTx.data[0] = 0x23;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 518 canmsgTx.data[1] = 0xFF;//Index LowByte
ngokystk 0:b4b94eb28093 519 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 520 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 521 //下位から1Byteずつdataに格納
ngokystk 0:b4b94eb28093 522
ngokystk 0:b4b94eb28093 523 //pc.printf("%d\r\n",rpm);
ngokystk 0:b4b94eb28093 524 if(rpm<0){
Tomo1213 3:c39c14cfc811 525 rpm=0xFFFFFFFF+rpm+1;
ngokystk 0:b4b94eb28093 526 }
ngokystk 0:b4b94eb28093 527 canmsgTx.data[7]=((rpm>>24)&0xFF);
ngokystk 0:b4b94eb28093 528 canmsgTx.data[6]=((rpm>>16)&0xFF);
ngokystk 0:b4b94eb28093 529 canmsgTx.data[5]=((rpm>>8)&0xFF);
ngokystk 0:b4b94eb28093 530 canmsgTx.data[4]=((rpm>>0)&0xFF);
ngokystk 0:b4b94eb28093 531
ngokystk 0:b4b94eb28093 532 //printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 533 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 534 wait_ms(1);
ngokystk 0:b4b94eb28093 535
ngokystk 0:b4b94eb28093 536 }
Tomo1213 3:c39c14cfc811 537
ngokystk 0:b4b94eb28093 538 void readActVel(int nodeID){
ngokystk 0:b4b94eb28093 539 //値が欲しいobjectのアドレスを送る
ngokystk 0:b4b94eb28093 540 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 541 canmsgTx.len = 4; //Data Length
ngokystk 0:b4b94eb28093 542 canmsgTx.data[0] = 0x40;//|0Byte:40|
ngokystk 0:b4b94eb28093 543 canmsgTx.data[1] = 0x6C;//Index LowByte
ngokystk 0:b4b94eb28093 544 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 545 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 546 canPort.write(canmsgTx);
ngokystk 0:b4b94eb28093 547 wait_ms(1);
ngokystk 0:b4b94eb28093 548 }
Tomo1213 1:b2bd1511307e 549
ngokystk 0:b4b94eb28093 550 void readActPos(int nodeID){
ngokystk 0:b4b94eb28093 551 //値が欲しいobjectのアドレスを送る
ngokystk 0:b4b94eb28093 552 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 553 canmsgTx.len = 4; //Data Length
ngokystk 0:b4b94eb28093 554 canmsgTx.data[0] = 0x40;//|0Byte:40|
ngokystk 0:b4b94eb28093 555 canmsgTx.data[1] = 0x64;//Index LowByte
ngokystk 0:b4b94eb28093 556 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 557 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 558 canPort.write(canmsgTx);
ngokystk 0:b4b94eb28093 559 wait_ms(1);
ngokystk 0:b4b94eb28093 560 }
Tomo1213 1:b2bd1511307e 561
ngokystk 0:b4b94eb28093 562 //加速度指定
ngokystk 0:b4b94eb28093 563 void sendProAcc(int nodeID,int rpm){
ngokystk 0:b4b94eb28093 564 if(rpm < 0){
ngokystk 0:b4b94eb28093 565 rpm += 0xFFFFFFFF;
ngokystk 0:b4b94eb28093 566 }
ngokystk 0:b4b94eb28093 567 // pc.printf("%drpm|0x%08x\r\n",rpm,rpm); //回転数送信データの表示
ngokystk 0:b4b94eb28093 568 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 569 canmsgTx.len = 8; //Data Length
ngokystk 0:b4b94eb28093 570 canmsgTx.data[0] = 0x23;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 571 canmsgTx.data[1] = 0x83;//Index LowByte
ngokystk 0:b4b94eb28093 572 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 573 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 574 //下位から1Byteずつdataに格納
ngokystk 0:b4b94eb28093 575 canmsgTx.data[4] = (rpm >> 0) & 0xFF;
ngokystk 0:b4b94eb28093 576 canmsgTx.data[5] = (rpm >> 8) & 0xFF;
ngokystk 0:b4b94eb28093 577 canmsgTx.data[6] = (rpm >> 16) & 0xFF;
ngokystk 0:b4b94eb28093 578 canmsgTx.data[7] = (rpm >> 24) & 0xFF;
ngokystk 0:b4b94eb28093 579 // printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 580 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 581 wait(0.01);
ngokystk 0:b4b94eb28093 582 //send Enable
ngokystk 0:b4b94eb28093 583 // pc.printf("Send Enable Command\r\n");
ngokystk 0:b4b94eb28093 584 sendCtrlEN(nodeID);
ngokystk 0:b4b94eb28093 585 wait(0.01);
ngokystk 0:b4b94eb28093 586 }
Tomo1213 1:b2bd1511307e 587
ngokystk 0:b4b94eb28093 588 //減速度指定
ngokystk 0:b4b94eb28093 589 void sendProDec(int nodeID,int rpm){
ngokystk 0:b4b94eb28093 590 if(rpm < 0){
ngokystk 0:b4b94eb28093 591 rpm += 0xFFFFFFFF;
Tomo1213 3:c39c14cfc811 592 }
ngokystk 0:b4b94eb28093 593 // pc.printf("%drpm|0x%08x\r\n",rpm,rpm); //回転数送信データの表示
ngokystk 0:b4b94eb28093 594 canmsgTx.id = 0x600+nodeID;
ngokystk 0:b4b94eb28093 595 canmsgTx.len = 8; //Data Length
ngokystk 0:b4b94eb28093 596 canmsgTx.data[0] = 0x23;//|0Byte:40|1Byte:2F|2Byte:2B|4Byte:23|other:22|
ngokystk 0:b4b94eb28093 597 canmsgTx.data[1] = 0x84;//Index LowByte
ngokystk 0:b4b94eb28093 598 canmsgTx.data[2] = 0x60;//Index HighByte
ngokystk 0:b4b94eb28093 599 canmsgTx.data[3] = 0x00;//sub-Index
ngokystk 0:b4b94eb28093 600 //下位から1Byteずつdataに格納
ngokystk 0:b4b94eb28093 601 canmsgTx.data[4] = (rpm >> 0) & 0xFF;
ngokystk 0:b4b94eb28093 602 canmsgTx.data[5] = (rpm >> 8) & 0xFF;
ngokystk 0:b4b94eb28093 603 canmsgTx.data[6] = (rpm >> 16) & 0xFF;
ngokystk 0:b4b94eb28093 604 canmsgTx.data[7] = (rpm >> 24) & 0xFF;
ngokystk 0:b4b94eb28093 605 // printCANTX(); //CAN送信データをPCに表示
ngokystk 0:b4b94eb28093 606 canPort.write(canmsgTx);//CANでデータ送信
ngokystk 0:b4b94eb28093 607 wait(0.01);
ngokystk 0:b4b94eb28093 608 //send Enable
ngokystk 0:b4b94eb28093 609 // pc.printf("Send Enable Command\r\n");
ngokystk 0:b4b94eb28093 610 sendCtrlEN(nodeID);
ngokystk 0:b4b94eb28093 611 wait(0.01);
ngokystk 0:b4b94eb28093 612 }
Tomo1213 1:b2bd1511307e 613
Tomo1213 1:b2bd1511307e 614
ngokystk 0:b4b94eb28093 615 //送信データの表示
ngokystk 0:b4b94eb28093 616 void printCANTX(void){
ngokystk 0:b4b94eb28093 617 //0x canID|Byte0|Byte1|Byte2|Byte3|Byte4|Byte5|Byte6|Byte7|
ngokystk 0:b4b94eb28093 618 pc.printf("0x%3x|",canmsgTx.id);
ngokystk 0:b4b94eb28093 619 for(char i=0;i < canmsgTx.len;i++){
ngokystk 0:b4b94eb28093 620 pc.printf("%02x|",canmsgTx.data[i]);
ngokystk 0:b4b94eb28093 621 }
ngokystk 0:b4b94eb28093 622 //pc.printf("\r\n");
ngokystk 0:b4b94eb28093 623 }
Tomo1213 1:b2bd1511307e 624
ngokystk 0:b4b94eb28093 625 //受信データの表示
Tomo1213 1:b2bd1511307e 626
ngokystk 0:b4b94eb28093 627 void printCANRX(void){
ngokystk 0:b4b94eb28093 628 //0x canID|Byte0|Byte1|Byte2|Byte3|Byte4|Byte5|Byte6|Byte7|
ngokystk 0:b4b94eb28093 629 //pc.printf("0x%3x|",canmsgRx.id);
ngokystk 0:b4b94eb28093 630 for(char i=0;i < canmsgRx.len;i++){
ngokystk 0:b4b94eb28093 631 //pc.printf("%02x|",canmsgRx.data[i]);
ngokystk 0:b4b94eb28093 632 }
ngokystk 0:b4b94eb28093 633 pc.printf("\r\n");
ngokystk 0:b4b94eb28093 634 }
Tomo1213 1:b2bd1511307e 635
ngokystk 0:b4b94eb28093 636 void CANdataRX(void){
ngokystk 0:b4b94eb28093 637 canPort.read(canmsgRx);
ngokystk 0:b4b94eb28093 638 printCANRX();
ngokystk 0:b4b94eb28093 639 }
Tomo1213 1:b2bd1511307e 640
ngokystk 0:b4b94eb28093 641 void SerialRX(void){
ngokystk 0:b4b94eb28093 642 Serialdata = pc.getc();
ngokystk 0:b4b94eb28093 643 //pc.printf("%c\r\n",Serialdata);
Tomo1213 5:a7c3f446a1f1 644 }