ライブラリ化を行った後
Dependencies: QEI accelerator bit_test cyclic_io cyclic_var cylinder event_var limit mbed mecanum motor_drive pid pid_encoder rs422_put sbdbt servo
Fork of 17robo_Practice1 by
main.cpp@49:b041c815c063, 2017-09-13 (annotated)
- Committer:
- echo_piyo
- Date:
- Wed Sep 13 01:25:07 2017 +0000
- Revision:
- 49:b041c815c063
- Parent:
- 48:96b5f5ebdfb0
- Child:
- 50:e4e1f38d1bd5
(?)????????????????????????????????; (enc).duty_enableWidth(min,max)?????????????????????; ????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
echo_piyo | 0:bf96e953cdb8 | 1 | #include "mbed.h" |
echo_piyo | 4:a6cc2f03e69b | 2 | #include "math.h" |
echo_piyo | 0:bf96e953cdb8 | 3 | #include "bit_test.h" |
echo_piyo | 0:bf96e953cdb8 | 4 | #include "RS422_put.h" |
echo_piyo | 0:bf96e953cdb8 | 5 | #include "sbdbt.h" |
echo_piyo | 0:bf96e953cdb8 | 6 | #include "mecanum.h" |
echo_piyo | 0:bf96e953cdb8 | 7 | #include "bno055_lib.h" |
echo_piyo | 0:bf96e953cdb8 | 8 | #include "bno055_use.h" |
echo_piyo | 0:bf96e953cdb8 | 9 | #include "pid.h" |
echo_piyo | 0:bf96e953cdb8 | 10 | #include "limit.h" |
echo_piyo | 4:a6cc2f03e69b | 11 | #include "accelerator.h" |
echo_piyo | 10:04f2a82cfd89 | 12 | #include "encorder.h" |
echo_piyo | 14:aac2f18f6779 | 13 | #include "cyclic.h" |
echo_piyo | 14:aac2f18f6779 | 14 | #include "cyclic_IO.h" |
echo_piyo | 15:0fdf483769bf | 15 | #include "cylinder.h" |
echo_piyo | 0:bf96e953cdb8 | 16 | |
echo_piyo | 0:bf96e953cdb8 | 17 | #define pc_baud 460800 |
echo_piyo | 0:bf96e953cdb8 | 18 | #define sbdbt_tx p13 |
echo_piyo | 0:bf96e953cdb8 | 19 | #define sbdbt_rx p14 |
echo_piyo | 0:bf96e953cdb8 | 20 | #define sbdbt_baud 115200 |
echo_piyo | 0:bf96e953cdb8 | 21 | #define rs422_tx p28 |
echo_piyo | 0:bf96e953cdb8 | 22 | #define rs422_rx p27 |
echo_piyo | 0:bf96e953cdb8 | 23 | #define rs422_baud 115200 |
echo_piyo | 3:9ef929639c4a | 24 | #define output_period 0.015 |
echo_piyo | 28:72b9af7e1700 | 25 | #define nucleo_num 6 |
echo_piyo | 0:bf96e953cdb8 | 26 | #define pi 3.141592 |
echo_piyo | 0:bf96e953cdb8 | 27 | #define n1_id 3 |
echo_piyo | 0:bf96e953cdb8 | 28 | #define n2_id 4 |
echo_piyo | 10:04f2a82cfd89 | 29 | #define n3_id 5 |
echo_piyo | 14:aac2f18f6779 | 30 | #define n4_id 6 |
echo_piyo | 14:aac2f18f6779 | 31 | #define n5_id 7 |
echo_piyo | 28:72b9af7e1700 | 32 | #define n6_id 8 |
echo_piyo | 5:6efda58ff71b | 33 | #define yaw_Kp 0.01 |
echo_piyo | 5:6efda58ff71b | 34 | #define yaw_Ki 0.01 |
echo_piyo | 5:6efda58ff71b | 35 | #define yaw_Kd 0.01 |
echo_piyo | 40:2d6888448ab2 | 36 | #define acceleration 20 //25 |
echo_piyo | 10:04f2a82cfd89 | 37 | #define pin_cylinder_on p17 |
echo_piyo | 10:04f2a82cfd89 | 38 | #define pin_cylinder_off p18 |
echo_piyo | 31:285c9898da03 | 39 | #define pin_interrupt_cylinder_min p23 |
echo_piyo | 12:1fec80ae8a2c | 40 | #define encoder_A p25 |
echo_piyo | 12:1fec80ae8a2c | 41 | #define encoder_B p26 |
echo_piyo | 40:2d6888448ab2 | 42 | #define enc_Kp 0.0400 |
echo_piyo | 33:64fd1bd83bac | 43 | #define enc_Ki 0.0001 |
echo_piyo | 33:64fd1bd83bac | 44 | #define enc_Kd 0.0003 |
echo_piyo | 34:02d605c68bf3 | 45 | #define mecanum_power 1.0 |
echo_piyo | 33:64fd1bd83bac | 46 | #define sword_power 0.8 |
echo_piyo | 33:64fd1bd83bac | 47 | #define sholder_power 0.8 |
echo_piyo | 47:6ea046767494 | 48 | #define pin_interrupt_sholderright_max p19 //p21 |
echo_piyo | 47:6ea046767494 | 49 | #define pin_interrupt_sholderright_min p20 //p22 |
echo_piyo | 33:64fd1bd83bac | 50 | #define pin_interrupt_sholderleft_max p7 |
echo_piyo | 33:64fd1bd83bac | 51 | #define pin_interrupt_sholderleft_min p8 |
echo_piyo | 37:fa738e34c4d3 | 52 | #define pin_servo p21 |
echo_piyo | 35:5e1ad00f26fb | 53 | #define servo_reload_time 1.0 |
echo_piyo | 43:605e5b0b9106 | 54 | #define pin_cylinder_reload p15 |
echo_piyo | 45:a32e8091901b | 55 | #define pin_sbdbt_pairing p12 |
echo_piyo | 45:a32e8091901b | 56 | #define pin_sbdbt_indicator p11 |
echo_piyo | 35:5e1ad00f26fb | 57 | //#define pin_servo_reload p29 // |
echo_piyo | 35:5e1ad00f26fb | 58 | //#define pin_interrupt_reload p30 // |
echo_piyo | 0:bf96e953cdb8 | 59 | |
echo_piyo | 45:a32e8091901b | 60 | DigitalOut led1(LED1); |
echo_piyo | 48:96b5f5ebdfb0 | 61 | DigitalOut led2(LED2); |
echo_piyo | 48:96b5f5ebdfb0 | 62 | DigitalOut led3(LED3); |
echo_piyo | 48:96b5f5ebdfb0 | 63 | DigitalOut led4(LED4); |
echo_piyo | 31:285c9898da03 | 64 | DigitalIn interrupt_cylinder_min(pin_interrupt_cylinder_min); |
echo_piyo | 0:bf96e953cdb8 | 65 | Serial pc(USBTX,USBRX); |
echo_piyo | 0:bf96e953cdb8 | 66 | RS422 rs422(rs422_tx, rs422_rx); |
echo_piyo | 45:a32e8091901b | 67 | Sbdbt sbdbt(sbdbt_tx, sbdbt_rx, pin_sbdbt_pairing); |
echo_piyo | 0:bf96e953cdb8 | 68 | Ticker output_timer; |
echo_piyo | 0:bf96e953cdb8 | 69 | Mecanum mecanum; |
echo_piyo | 0:bf96e953cdb8 | 70 | Bno055 bno055; |
echo_piyo | 2:d5b8f8e62923 | 71 | Position_pid yaw_pid; |
echo_piyo | 4:a6cc2f03e69b | 72 | Accel v1; |
echo_piyo | 4:a6cc2f03e69b | 73 | Accel v2; |
echo_piyo | 4:a6cc2f03e69b | 74 | Accel v3; |
echo_piyo | 4:a6cc2f03e69b | 75 | Accel v4; |
echo_piyo | 15:0fdf483769bf | 76 | Cylinder cylinder(pin_cylinder_on,pin_cylinder_off); |
echo_piyo | 26:3280d0300b04 | 77 | Cyclic sword; |
echo_piyo | 31:285c9898da03 | 78 | Cyclic cyclic_cylinder_position; |
echo_piyo | 31:285c9898da03 | 79 | DigitalIn interrupt_sholderright_min(pin_interrupt_sholderright_min); |
echo_piyo | 31:285c9898da03 | 80 | DigitalIn interrupt_sholderright_max(pin_interrupt_sholderright_max); |
echo_piyo | 31:285c9898da03 | 81 | DigitalIn interrupt_sholderleft_min(pin_interrupt_sholderleft_min); |
echo_piyo | 31:285c9898da03 | 82 | DigitalIn interrupt_sholderleft_max(pin_interrupt_sholderleft_max); |
echo_piyo | 35:5e1ad00f26fb | 83 | Encoder enc_cylinder(encoder_A,encoder_B); |
echo_piyo | 38:b071512af5ca | 84 | Cyclic cyclic_servo; |
echo_piyo | 42:63aedf71f4d1 | 85 | Cyclic_IO cylinder_reload(pin_cylinder_reload); |
echo_piyo | 31:285c9898da03 | 86 | |
echo_piyo | 35:5e1ad00f26fb | 87 | //追加 |
echo_piyo | 35:5e1ad00f26fb | 88 | PwmOut servo(pin_servo); |
echo_piyo | 35:5e1ad00f26fb | 89 | Timeout timer_servo; |
echo_piyo | 45:a32e8091901b | 90 | DigitalOut sbdbt_indigator(pin_sbdbt_indicator); |
echo_piyo | 33:64fd1bd83bac | 91 | //Servo servo_reload(pin_servo_reload); |
echo_piyo | 33:64fd1bd83bac | 92 | //DigitalIn interrupt_reload(pin_interrupt_reload); |
echo_piyo | 9:6486f4b3ac50 | 93 | |
echo_piyo | 0:bf96e953cdb8 | 94 | void setup(); |
echo_piyo | 0:bf96e953cdb8 | 95 | void output(); |
echo_piyo | 15:0fdf483769bf | 96 | void motor_cal(); |
echo_piyo | 16:e49df474e4c6 | 97 | void cylinder_cal(); |
echo_piyo | 10:04f2a82cfd89 | 98 | void boost(); |
echo_piyo | 12:1fec80ae8a2c | 99 | void cylinder_origin(); |
echo_piyo | 38:b071512af5ca | 100 | void cylinder_origin_first(); |
echo_piyo | 26:3280d0300b04 | 101 | void sword_cal(); |
echo_piyo | 35:5e1ad00f26fb | 102 | void servo_origin(); |
echo_piyo | 31:285c9898da03 | 103 | float shoulder_right_cal(); |
echo_piyo | 31:285c9898da03 | 104 | float shoulder_left_cal(); |
echo_piyo | 42:63aedf71f4d1 | 105 | |
echo_piyo | 39:6735743ac0f1 | 106 | //output |
echo_piyo | 2:d5b8f8e62923 | 107 | float yaw, target_yaw; |
echo_piyo | 39:6735743ac0f1 | 108 | //cylinder_origin |
echo_piyo | 38:b071512af5ca | 109 | int cylinder_origin_flag = 0; |
echo_piyo | 39:6735743ac0f1 | 110 | //cylinder |
echo_piyo | 39:6735743ac0f1 | 111 | float cylinder_pwm; |
echo_piyo | 39:6735743ac0f1 | 112 | int cylinder_pos_num = 0; |
echo_piyo | 42:63aedf71f4d1 | 113 | float cylinder_pos[3] = {0.0,90.0,325.0}; |
echo_piyo | 0:bf96e953cdb8 | 114 | |
echo_piyo | 31:285c9898da03 | 115 | //riseEventそのうちClassにしたい |
echo_piyo | 31:285c9898da03 | 116 | short state; |
echo_piyo | 31:285c9898da03 | 117 | int riseEvent(int input) |
echo_piyo | 31:285c9898da03 | 118 | { |
echo_piyo | 31:285c9898da03 | 119 | state = ((state<<1)|input)&3; |
echo_piyo | 31:285c9898da03 | 120 | if(state == 1) { |
echo_piyo | 31:285c9898da03 | 121 | return 1; |
echo_piyo | 31:285c9898da03 | 122 | } else { |
echo_piyo | 31:285c9898da03 | 123 | return 0; |
echo_piyo | 31:285c9898da03 | 124 | } |
echo_piyo | 31:285c9898da03 | 125 | } |
echo_piyo | 31:285c9898da03 | 126 | |
echo_piyo | 0:bf96e953cdb8 | 127 | int main() |
echo_piyo | 0:bf96e953cdb8 | 128 | { |
echo_piyo | 0:bf96e953cdb8 | 129 | setup(); |
echo_piyo | 2:d5b8f8e62923 | 130 | while(1) { |
echo_piyo | 48:96b5f5ebdfb0 | 131 | led1 = interrupt_sholderleft_max; |
echo_piyo | 48:96b5f5ebdfb0 | 132 | led2 = interrupt_sholderleft_min; |
echo_piyo | 48:96b5f5ebdfb0 | 133 | led3 = interrupt_sholderright_max; |
echo_piyo | 48:96b5f5ebdfb0 | 134 | led4 = interrupt_sholderright_min; |
echo_piyo | 31:285c9898da03 | 135 | //pc.printf("Pulses is: %lo\tdeg :%f\r\n",enc_cylinder.pulse(),enc_cylinder.deg()); |
echo_piyo | 40:2d6888448ab2 | 136 | //pc.printf("rise state : %d\r\n",cyclic_servo.getState()); |
echo_piyo | 45:a32e8091901b | 137 | pc.printf("Sbdbtstate : %d\r\n",sbdbt.get_pairingState()); |
echo_piyo | 0:bf96e953cdb8 | 138 | } |
echo_piyo | 0:bf96e953cdb8 | 139 | } |
echo_piyo | 0:bf96e953cdb8 | 140 | |
echo_piyo | 0:bf96e953cdb8 | 141 | void setup() |
echo_piyo | 0:bf96e953cdb8 | 142 | { |
echo_piyo | 40:2d6888448ab2 | 143 | wait(2.0); |
echo_piyo | 19:76a387e4bcf6 | 144 | bno055.begin(); |
echo_piyo | 40:2d6888448ab2 | 145 | wait(1.0); |
echo_piyo | 19:76a387e4bcf6 | 146 | bno055.firstRead(); |
echo_piyo | 0:bf96e953cdb8 | 147 | pc.baud(pc_baud); |
echo_piyo | 0:bf96e953cdb8 | 148 | sbdbt.begin(sbdbt_baud); |
echo_piyo | 0:bf96e953cdb8 | 149 | rs422.begin(rs422_baud); |
echo_piyo | 38:b071512af5ca | 150 | cylinder_origin_first(); |
echo_piyo | 49:b041c815c063 | 151 | cylinder_pos_num = 2; //セットアップタイムでの初期装填のため |
echo_piyo | 0:bf96e953cdb8 | 152 | output_timer.attach(&output, output_period); |
echo_piyo | 2:d5b8f8e62923 | 153 | yaw_pid.setup(yaw_Kp, yaw_Ki, yaw_Kd); |
echo_piyo | 39:6735743ac0f1 | 154 | mecanum.setupdeg(bno055.getYawRad()); //基盤が前後逆の場合+180 |
echo_piyo | 4:a6cc2f03e69b | 155 | v1.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 156 | v2.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 157 | v3.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 158 | v4.setup(acceleration,output_period); |
echo_piyo | 31:285c9898da03 | 159 | enc_cylinder.setup(100); |
echo_piyo | 13:dfae731e239f | 160 | enc_cylinder.set_parameter(enc_Kp,enc_Ki,enc_Kd); |
echo_piyo | 35:5e1ad00f26fb | 161 | |
echo_piyo | 35:5e1ad00f26fb | 162 | //追加 |
echo_piyo | 35:5e1ad00f26fb | 163 | servo.period(0.020); |
echo_piyo | 12:1fec80ae8a2c | 164 | } |
echo_piyo | 12:1fec80ae8a2c | 165 | |
echo_piyo | 36:dca1081c19b3 | 166 | //Sword |
echo_piyo | 35:5e1ad00f26fb | 167 | float shoulder_right_cal() |
echo_piyo | 15:0fdf483769bf | 168 | { |
echo_piyo | 40:2d6888448ab2 | 169 | if(interrupt_sholderright_max==0&&sbdbt.sankaku==1) { |
echo_piyo | 31:285c9898da03 | 170 | return 0.0; |
echo_piyo | 31:285c9898da03 | 171 | } |
echo_piyo | 40:2d6888448ab2 | 172 | if(interrupt_sholderright_min==0&&sbdbt.batu==1) { |
echo_piyo | 33:64fd1bd83bac | 173 | return 0.0; |
echo_piyo | 31:285c9898da03 | 174 | } |
echo_piyo | 31:285c9898da03 | 175 | return (-sbdbt.sankaku*0.8+sbdbt.batu*0.8); |
echo_piyo | 31:285c9898da03 | 176 | } |
echo_piyo | 31:285c9898da03 | 177 | |
echo_piyo | 35:5e1ad00f26fb | 178 | float shoulder_left_cal() |
echo_piyo | 35:5e1ad00f26fb | 179 | { |
echo_piyo | 40:2d6888448ab2 | 180 | if(interrupt_sholderleft_max==0&&sbdbt.sankaku==1) { |
echo_piyo | 31:285c9898da03 | 181 | return 0.0; |
echo_piyo | 31:285c9898da03 | 182 | } |
echo_piyo | 40:2d6888448ab2 | 183 | if(interrupt_sholderleft_min==0&&sbdbt.batu==1) { |
echo_piyo | 35:5e1ad00f26fb | 184 | return 0.0; |
echo_piyo | 31:285c9898da03 | 185 | } |
echo_piyo | 40:2d6888448ab2 | 186 | return (-sbdbt.sankaku*0.8+sbdbt.batu*0.8); |
echo_piyo | 31:285c9898da03 | 187 | } |
echo_piyo | 31:285c9898da03 | 188 | void sword_cal() |
echo_piyo | 31:285c9898da03 | 189 | { |
echo_piyo | 26:3280d0300b04 | 190 | sword.cyclic(sbdbt.maru); |
echo_piyo | 17:5c4718c603dc | 191 | } |
echo_piyo | 15:0fdf483769bf | 192 | |
echo_piyo | 36:dca1081c19b3 | 193 | //cylinder |
echo_piyo | 38:b071512af5ca | 194 | void cylinder_origin_first() |
echo_piyo | 31:285c9898da03 | 195 | { |
echo_piyo | 48:96b5f5ebdfb0 | 196 | while(interrupt_cylinder_min == 1){ |
echo_piyo | 40:2d6888448ab2 | 197 | rs422.put(5, -0.4, 0.0); |
echo_piyo | 12:1fec80ae8a2c | 198 | } |
echo_piyo | 48:96b5f5ebdfb0 | 199 | rs422.put(5, 0.0, 0.0); |
echo_piyo | 31:285c9898da03 | 200 | enc_cylinder.origin(); |
echo_piyo | 0:bf96e953cdb8 | 201 | } |
echo_piyo | 38:b071512af5ca | 202 | |
echo_piyo | 42:63aedf71f4d1 | 203 | //cylinder_origin_flagを1にすることで動作する |
echo_piyo | 38:b071512af5ca | 204 | void cylinder_origin() |
echo_piyo | 38:b071512af5ca | 205 | { |
echo_piyo | 45:a32e8091901b | 206 | if(interrupt_cylinder_min == 0&&cylinder_origin_flag == 1) { |
echo_piyo | 39:6735743ac0f1 | 207 | cylinder_origin_flag = 0; |
echo_piyo | 39:6735743ac0f1 | 208 | enc_cylinder.origin(); |
echo_piyo | 39:6735743ac0f1 | 209 | cylinder_pos_num = 0; |
echo_piyo | 45:a32e8091901b | 210 | } else if(cylinder_origin_flag == 1) { |
echo_piyo | 42:63aedf71f4d1 | 211 | rs422.put(5, -0.8, 0.0); |
echo_piyo | 38:b071512af5ca | 212 | } |
echo_piyo | 38:b071512af5ca | 213 | } |
echo_piyo | 38:b071512af5ca | 214 | |
echo_piyo | 28:72b9af7e1700 | 215 | //追記(動作未確認) |
echo_piyo | 19:76a387e4bcf6 | 216 | void cylinder_cal() |
echo_piyo | 31:285c9898da03 | 217 | { |
echo_piyo | 31:285c9898da03 | 218 | cylinder.cyclic(sbdbt.shikaku); //cylinder ON/OFF |
echo_piyo | 35:5e1ad00f26fb | 219 | |
echo_piyo | 35:5e1ad00f26fb | 220 | if(riseEvent(sbdbt.right)) { //cylinder degset |
echo_piyo | 31:285c9898da03 | 221 | cylinder_pos_num++; |
echo_piyo | 35:5e1ad00f26fb | 222 | if(cylinder_pos_num >= 3) { |
echo_piyo | 42:63aedf71f4d1 | 223 | //cylinder_pos_num = 0; |
echo_piyo | 42:63aedf71f4d1 | 224 | cylinder_origin_flag=1; |
echo_piyo | 31:285c9898da03 | 225 | } |
echo_piyo | 31:285c9898da03 | 226 | } |
echo_piyo | 31:285c9898da03 | 227 | enc_cylinder.cal((float)cylinder_pos[cylinder_pos_num],output_period); //コントローラで数値設定 |
echo_piyo | 35:5e1ad00f26fb | 228 | |
echo_piyo | 38:b071512af5ca | 229 | //pc.printf("terget\t%f\tnow_deg\t%f\tnow_pulse\t%d\tpwm\t%f\r\n",cylinder_pos[cylinder_pos_num],enc_cylinder.deg(),enc_cylinder.pulse(),enc_cylinder.duty()); |
echo_piyo | 28:72b9af7e1700 | 230 | |
echo_piyo | 31:285c9898da03 | 231 | //リロード機構完成後 |
echo_piyo | 31:285c9898da03 | 232 | /* |
echo_piyo | 31:285c9898da03 | 233 | if(cylinder.getInState() == 1){ |
echo_piyo | 31:285c9898da03 | 234 | if(interrupt_cylinder_min)servo_reload = 1.0; |
echo_piyo | 31:285c9898da03 | 235 | }else{ |
echo_piyo | 31:285c9898da03 | 236 | servo_reload = 0.0; |
echo_piyo | 31:285c9898da03 | 237 | reload_magazine_flag = 1; |
echo_piyo | 31:285c9898da03 | 238 | } |
echo_piyo | 31:285c9898da03 | 239 | |
echo_piyo | 31:285c9898da03 | 240 | if(reload_magazine_flag == 1){ |
echo_piyo | 31:285c9898da03 | 241 | rs422.put(n6_id, 0.8, 0.0); |
echo_piyo | 31:285c9898da03 | 242 | if(interrupt_reload == 1)reload_magazine_flag = 0; |
echo_piyo | 31:285c9898da03 | 243 | } |
echo_piyo | 31:285c9898da03 | 244 | */ |
echo_piyo | 19:76a387e4bcf6 | 245 | } |
echo_piyo | 38:b071512af5ca | 246 | |
echo_piyo | 45:a32e8091901b | 247 | void servo_max() |
echo_piyo | 45:a32e8091901b | 248 | { |
echo_piyo | 45:a32e8091901b | 249 | servo.pulsewidth(0.0022); |
echo_piyo | 35:5e1ad00f26fb | 250 | } |
echo_piyo | 38:b071512af5ca | 251 | void servo_min() |
echo_piyo | 35:5e1ad00f26fb | 252 | { |
echo_piyo | 35:5e1ad00f26fb | 253 | servo.pulsewidth(0.0010); |
echo_piyo | 38:b071512af5ca | 254 | } |
echo_piyo | 45:a32e8091901b | 255 | void servo_out() |
echo_piyo | 45:a32e8091901b | 256 | { |
echo_piyo | 39:6735743ac0f1 | 257 | cyclic_servo.cyclic(sbdbt.down); //setServoControl |
echo_piyo | 45:a32e8091901b | 258 | if(cyclic_servo.getState()==0) { |
echo_piyo | 39:6735743ac0f1 | 259 | servo_min(); |
echo_piyo | 45:a32e8091901b | 260 | } else if(cyclic_servo.getState()==1) { |
echo_piyo | 39:6735743ac0f1 | 261 | servo_max(); |
echo_piyo | 38:b071512af5ca | 262 | } |
echo_piyo | 35:5e1ad00f26fb | 263 | } |
echo_piyo | 35:5e1ad00f26fb | 264 | |
echo_piyo | 36:dca1081c19b3 | 265 | |
echo_piyo | 36:dca1081c19b3 | 266 | //boost |
echo_piyo | 31:285c9898da03 | 267 | void boost() |
echo_piyo | 31:285c9898da03 | 268 | { |
echo_piyo | 31:285c9898da03 | 269 | if(sbdbt.r2) { |
echo_piyo | 10:04f2a82cfd89 | 270 | mecanum.boost_forward(); |
echo_piyo | 10:04f2a82cfd89 | 271 | } |
echo_piyo | 31:285c9898da03 | 272 | if(sbdbt.l2) { |
echo_piyo | 10:04f2a82cfd89 | 273 | mecanum.boost_back(); |
echo_piyo | 10:04f2a82cfd89 | 274 | } |
echo_piyo | 26:3280d0300b04 | 275 | /* |
echo_piyo | 10:04f2a82cfd89 | 276 | if(sbdbt.shikaku) { |
echo_piyo | 10:04f2a82cfd89 | 277 | mecanum.boost_left(); |
echo_piyo | 10:04f2a82cfd89 | 278 | } |
echo_piyo | 10:04f2a82cfd89 | 279 | if(sbdbt.maru) { |
echo_piyo | 10:04f2a82cfd89 | 280 | mecanum.boost_right(); |
echo_piyo | 10:04f2a82cfd89 | 281 | } |
echo_piyo | 26:3280d0300b04 | 282 | */ |
echo_piyo | 10:04f2a82cfd89 | 283 | } |
echo_piyo | 10:04f2a82cfd89 | 284 | |
echo_piyo | 36:dca1081c19b3 | 285 | //mecanum |
echo_piyo | 15:0fdf483769bf | 286 | void motor_cal() |
echo_piyo | 5:6efda58ff71b | 287 | { |
echo_piyo | 4:a6cc2f03e69b | 288 | yaw = bno055.getYawRad(); |
echo_piyo | 4:a6cc2f03e69b | 289 | target_yaw = yaw; |
echo_piyo | 4:a6cc2f03e69b | 290 | yaw_pid.cal(target_yaw, yaw, output_period); |
echo_piyo | 4:a6cc2f03e69b | 291 | mecanum.sbdbt_cal(sbdbt.left_x, sbdbt.left_y, sbdbt.l1, sbdbt.r1, yaw_pid.duty(), bno055.getYawRad()); |
echo_piyo | 5:6efda58ff71b | 292 | // pc.printf("%f\t data %f\t %f\t %f\t %f\t\r\n", bno055.getYawRad(), sbdbt.left_x, sbdbt.left_y, mecanum.VX(), mecanum.VY()); |
echo_piyo | 35:5e1ad00f26fb | 293 | } |
echo_piyo | 35:5e1ad00f26fb | 294 | void output() |
echo_piyo | 35:5e1ad00f26fb | 295 | { |
echo_piyo | 35:5e1ad00f26fb | 296 | motor_cal(); |
echo_piyo | 35:5e1ad00f26fb | 297 | cylinder_cal(); |
echo_piyo | 35:5e1ad00f26fb | 298 | sword_cal(); |
echo_piyo | 38:b071512af5ca | 299 | servo_out(); |
echo_piyo | 38:b071512af5ca | 300 | cylinder_origin(); |
echo_piyo | 35:5e1ad00f26fb | 301 | //boost(); |
echo_piyo | 45:a32e8091901b | 302 | |
echo_piyo | 48:96b5f5ebdfb0 | 303 | //led1 = sbdbt.get_pairingState(); |
echo_piyo | 45:a32e8091901b | 304 | sbdbt_indigator = sbdbt.get_pairingState(); |
echo_piyo | 45:a32e8091901b | 305 | |
echo_piyo | 49:b041c815c063 | 306 | if(sbdbt.up)cylinder_origin_flag = 1; |
echo_piyo | 49:b041c815c063 | 307 | if(sbdbt.left)bno055.yaw_origin(); |
echo_piyo | 49:b041c815c063 | 308 | cylinder_reload.cyclic(sbdbt.down); |
echo_piyo | 45:a32e8091901b | 309 | |
echo_piyo | 35:5e1ad00f26fb | 310 | static int counter; |
echo_piyo | 35:5e1ad00f26fb | 311 | int id[nucleo_num] = {n1_id, n2_id, n3_id, n4_id, n5_id, n6_id}; |
echo_piyo | 45:a32e8091901b | 312 | |
echo_piyo | 45:a32e8091901b | 313 | //sbdbtがpairingしている場合のみ動作 |
echo_piyo | 45:a32e8091901b | 314 | if(sbdbt.get_pairingState()) { |
echo_piyo | 45:a32e8091901b | 315 | switch (counter) { |
echo_piyo | 45:a32e8091901b | 316 | case 0: |
echo_piyo | 45:a32e8091901b | 317 | rs422.put(id[counter], v1.duty((mecanum.v1()*mecanum_power)+(sbdbt.right_y*0.5)), v3.duty((mecanum.v3()*mecanum_power)+(sbdbt.right_y*0.5))); |
echo_piyo | 45:a32e8091901b | 318 | counter++; |
echo_piyo | 45:a32e8091901b | 319 | break; |
echo_piyo | 45:a32e8091901b | 320 | case 1: |
echo_piyo | 45:a32e8091901b | 321 | //.duty(<cal>*<powerControle>+(<boost>*0.5)) |
echo_piyo | 45:a32e8091901b | 322 | rs422.put(id[counter], v2.duty((mecanum.v2()*mecanum_power)-(sbdbt.right_y*0.5)), v4.duty((mecanum.v4()*mecanum_power)-(sbdbt.right_y*0.5))); |
echo_piyo | 45:a32e8091901b | 323 | counter ++; |
echo_piyo | 45:a32e8091901b | 324 | break; |
echo_piyo | 45:a32e8091901b | 325 | case 2: |
echo_piyo | 49:b041c815c063 | 326 | rs422.put(id[counter], -1*enc_cylinder.duty_enableWidth(-.0,5.0), 0.0); |
echo_piyo | 45:a32e8091901b | 327 | counter ++; |
echo_piyo | 45:a32e8091901b | 328 | break; |
echo_piyo | 45:a32e8091901b | 329 | case 3: |
echo_piyo | 48:96b5f5ebdfb0 | 330 | rs422.put(id[counter], -1*shoulder_right_cal()*sholder_power,shoulder_left_cal()*sholder_power); |
echo_piyo | 45:a32e8091901b | 331 | counter ++; |
echo_piyo | 45:a32e8091901b | 332 | break; |
echo_piyo | 45:a32e8091901b | 333 | case 4: |
echo_piyo | 45:a32e8091901b | 334 | rs422.put(id[counter], ((float)sword.getState()*sword_power),0.0); |
echo_piyo | 45:a32e8091901b | 335 | counter = 0; |
echo_piyo | 45:a32e8091901b | 336 | break; |
echo_piyo | 45:a32e8091901b | 337 | default: |
echo_piyo | 45:a32e8091901b | 338 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 339 | } |
echo_piyo | 45:a32e8091901b | 340 | }else{ |
echo_piyo | 48:96b5f5ebdfb0 | 341 | switch (counter) { |
echo_piyo | 48:96b5f5ebdfb0 | 342 | case 0: |
echo_piyo | 48:96b5f5ebdfb0 | 343 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 344 | counter++; |
echo_piyo | 48:96b5f5ebdfb0 | 345 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 346 | case 1: |
echo_piyo | 48:96b5f5ebdfb0 | 347 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 348 | counter ++; |
echo_piyo | 48:96b5f5ebdfb0 | 349 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 350 | case 2: |
echo_piyo | 48:96b5f5ebdfb0 | 351 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 352 | counter ++; |
echo_piyo | 48:96b5f5ebdfb0 | 353 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 354 | case 3: |
echo_piyo | 48:96b5f5ebdfb0 | 355 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 356 | counter ++; |
echo_piyo | 48:96b5f5ebdfb0 | 357 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 358 | case 4: |
echo_piyo | 48:96b5f5ebdfb0 | 359 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 360 | counter = 0; |
echo_piyo | 48:96b5f5ebdfb0 | 361 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 362 | default: |
echo_piyo | 48:96b5f5ebdfb0 | 363 | break; |
echo_piyo | 45:a32e8091901b | 364 | } |
echo_piyo | 45:a32e8091901b | 365 | } |
echo_piyo | 14:aac2f18f6779 | 366 | } |