Dependencies:   uw_28015 mbed move4wheel2 EC CruizCore_R6093U CruizCore_R1370P

Committer:
la00noix
Date:
Tue Mar 19 13:20:23 2019 +0000
Revision:
0:b87fd8dd4322
Child:
1:26fc1b2f1c42
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
la00noix 0:b87fd8dd4322 1 #include "EC.h"
la00noix 0:b87fd8dd4322 2 #include "R1370P.h"
la00noix 0:b87fd8dd4322 3 #include "move4wheel.h"
la00noix 0:b87fd8dd4322 4 #include "mbed.h"
la00noix 0:b87fd8dd4322 5 #include "math.h"
la00noix 0:b87fd8dd4322 6 #include "PathFollowing.h"
la00noix 0:b87fd8dd4322 7 #include "movement.h"
la00noix 0:b87fd8dd4322 8 #include "maxonsetting.h"
la00noix 0:b87fd8dd4322 9 #include "manual.h"
la00noix 0:b87fd8dd4322 10 #include "can.h"
la00noix 0:b87fd8dd4322 11
la00noix 0:b87fd8dd4322 12 #define PI 3.141592
la00noix 0:b87fd8dd4322 13
la00noix 0:b87fd8dd4322 14 int id1_value[7]= {0};
la00noix 0:b87fd8dd4322 15
la00noix 0:b87fd8dd4322 16 //-----手動用の変数宣言--------------------------------------------------------------------------//
la00noix 0:b87fd8dd4322 17 int stick_theta; //ジョイスティックの角度
la00noix 0:b87fd8dd4322 18 int manual_xout,manual_yout; //フィールド座標系のx,y方向の速度
la00noix 0:b87fd8dd4322 19 int manual_realxout,manual_realyout; //機体座標系のx,y方向の速度
la00noix 0:b87fd8dd4322 20 int manual_rout; //旋回速度
la00noix 0:b87fd8dd4322 21
la00noix 0:b87fd8dd4322 22 void CalManualOut(int v,int r_out) //vはθ方向の速度、r_outは旋回速度(正の値)
la00noix 0:b87fd8dd4322 23 //PS3ジョイスティックの x=127.5 かつ y>127.5 の直線を0°としてθをとる
la00noix 0:b87fd8dd4322 24 {
la00noix 0:b87fd8dd4322 25 stick_theta = (short)((id1_value[1]<<8) | id1_value[2]);
la00noix 0:b87fd8dd4322 26 //debug_printf("stick = %d\n\r",stick_theta);
la00noix 0:b87fd8dd4322 27
la00noix 0:b87fd8dd4322 28 //ジョイスティック方向の速度をフィールド座標系の速度に変換
la00noix 0:b87fd8dd4322 29 manual_xout = v * sin(PI*stick_theta/180);
la00noix 0:b87fd8dd4322 30 manual_yout = -v * cos(PI*stick_theta/180);
la00noix 0:b87fd8dd4322 31
la00noix 0:b87fd8dd4322 32 //フィールド座標系の速度を機体座標系の速度に変換
la00noix 0:b87fd8dd4322 33 manual_realxout = manual_xout * cos(PI*now_angle/180) + manual_yout * sin(PI*now_angle/180);
la00noix 0:b87fd8dd4322 34 manual_realyout = -manual_xout * sin(PI*now_angle/180) + manual_yout * cos(PI*now_angle/180);
la00noix 0:b87fd8dd4322 35
la00noix 0:b87fd8dd4322 36 if(id1_value[4] == 1) { //旋回速度を代入
la00noix 0:b87fd8dd4322 37 manual_rout = 0;
la00noix 0:b87fd8dd4322 38 } else if(id1_value[4] == 2) {
la00noix 0:b87fd8dd4322 39 manual_rout = r_out;
la00noix 0:b87fd8dd4322 40 } else if(id1_value[4] == 3) {
la00noix 0:b87fd8dd4322 41 manual_rout = -r_out;
la00noix 0:b87fd8dd4322 42 }
la00noix 0:b87fd8dd4322 43
la00noix 0:b87fd8dd4322 44
la00noix 0:b87fd8dd4322 45 }
la00noix 0:b87fd8dd4322 46
la00noix 0:b87fd8dd4322 47 void ManualOut(int slow_v, int slow_r, int fast_v, int fast_r)
la00noix 0:b87fd8dd4322 48 {
la00noix 0:b87fd8dd4322 49
la00noix 0:b87fd8dd4322 50 calc_gyro();
la00noix 0:b87fd8dd4322 51
la00noix 0:b87fd8dd4322 52 if(id1_value[3]==1) { //BOTTONR1押したら減速
la00noix 0:b87fd8dd4322 53 CalManualOut(slow_v,slow_r);
la00noix 0:b87fd8dd4322 54 } else {
la00noix 0:b87fd8dd4322 55 CalManualOut(fast_v,fast_r);
la00noix 0:b87fd8dd4322 56 }
la00noix 0:b87fd8dd4322 57
la00noix 0:b87fd8dd4322 58 if(id1_value[5] == 1) { //ニュートラルポジションなら出力0
la00noix 0:b87fd8dd4322 59 output(0,0,0,0);
la00noix 0:b87fd8dd4322 60 base(manual_rout,manual_rout,manual_rout,manual_rout,4095);
la00noix 0:b87fd8dd4322 61 } else {
la00noix 0:b87fd8dd4322 62 CalMotorOut(manual_realxout,manual_realyout,0);
la00noix 0:b87fd8dd4322 63 base(GetMotorOut(0)+manual_rout,GetMotorOut(1)+manual_rout,GetMotorOut(2)+manual_rout,GetMotorOut(3)+manual_rout,4095);
la00noix 0:b87fd8dd4322 64 }
la00noix 0:b87fd8dd4322 65
la00noix 0:b87fd8dd4322 66 MaxonControl(m1,m2,m3,m4);
la00noix 0:b87fd8dd4322 67 debug_printf("m1=%d m2=%d m3=%d m4=%d now_angle=%f\n\r",m1,m2,m3,m4,now_angle);
la00noix 0:b87fd8dd4322 68 }