sampleProgram
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_fuzi by
main.cpp@54:a88208d9bc1d, 2017-09-16 (annotated)
- Committer:
- echo_piyo
- Date:
- Sat Sep 16 01:05:23 2017 +0000
- Revision:
- 54:a88208d9bc1d
- Parent:
- 53:701dc7886fff
- Child:
- 55:2dd2f161ebaf
(?)9?16??????????????
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 | 50:e4e1f38d1bd5 | 16 | #include "varEvent.h" |
echo_piyo | 0:bf96e953cdb8 | 17 | |
echo_piyo | 0:bf96e953cdb8 | 18 | #define pc_baud 460800 |
echo_piyo | 0:bf96e953cdb8 | 19 | #define sbdbt_tx p13 |
echo_piyo | 0:bf96e953cdb8 | 20 | #define sbdbt_rx p14 |
echo_piyo | 0:bf96e953cdb8 | 21 | #define sbdbt_baud 115200 |
echo_piyo | 0:bf96e953cdb8 | 22 | #define rs422_tx p28 |
echo_piyo | 0:bf96e953cdb8 | 23 | #define rs422_rx p27 |
echo_piyo | 0:bf96e953cdb8 | 24 | #define rs422_baud 115200 |
echo_piyo | 3:9ef929639c4a | 25 | #define output_period 0.015 |
echo_piyo | 28:72b9af7e1700 | 26 | #define nucleo_num 6 |
echo_piyo | 0:bf96e953cdb8 | 27 | #define pi 3.141592 |
echo_piyo | 0:bf96e953cdb8 | 28 | #define n1_id 3 |
echo_piyo | 0:bf96e953cdb8 | 29 | #define n2_id 4 |
echo_piyo | 10:04f2a82cfd89 | 30 | #define n3_id 5 |
echo_piyo | 14:aac2f18f6779 | 31 | #define n4_id 6 |
echo_piyo | 14:aac2f18f6779 | 32 | #define n5_id 7 |
echo_piyo | 28:72b9af7e1700 | 33 | #define n6_id 8 |
echo_piyo | 5:6efda58ff71b | 34 | #define yaw_Kp 0.01 |
echo_piyo | 5:6efda58ff71b | 35 | #define yaw_Ki 0.01 |
echo_piyo | 5:6efda58ff71b | 36 | #define yaw_Kd 0.01 |
echo_piyo | 54:a88208d9bc1d | 37 | #define acceleration 15 //25 |
echo_piyo | 10:04f2a82cfd89 | 38 | #define pin_cylinder_on p17 |
echo_piyo | 10:04f2a82cfd89 | 39 | #define pin_cylinder_off p18 |
echo_piyo | 31:285c9898da03 | 40 | #define pin_interrupt_cylinder_min p23 |
echo_piyo | 12:1fec80ae8a2c | 41 | #define encoder_A p25 |
echo_piyo | 12:1fec80ae8a2c | 42 | #define encoder_B p26 |
echo_piyo | 40:2d6888448ab2 | 43 | #define enc_Kp 0.0400 |
echo_piyo | 33:64fd1bd83bac | 44 | #define enc_Ki 0.0001 |
echo_piyo | 33:64fd1bd83bac | 45 | #define enc_Kd 0.0003 |
echo_piyo | 34:02d605c68bf3 | 46 | #define mecanum_power 1.0 |
echo_piyo | 52:f5ae47e683fa | 47 | #define sword_power 1.0 |
echo_piyo | 52:f5ae47e683fa | 48 | #define sholder_power 1.0 |
echo_piyo | 47:6ea046767494 | 49 | #define pin_interrupt_sholderright_max p19 //p21 |
echo_piyo | 47:6ea046767494 | 50 | #define pin_interrupt_sholderright_min p20 //p22 |
echo_piyo | 33:64fd1bd83bac | 51 | #define pin_interrupt_sholderleft_max p7 |
echo_piyo | 33:64fd1bd83bac | 52 | #define pin_interrupt_sholderleft_min p8 |
echo_piyo | 37:fa738e34c4d3 | 53 | #define pin_servo p21 |
echo_piyo | 35:5e1ad00f26fb | 54 | #define servo_reload_time 1.0 |
echo_piyo | 43:605e5b0b9106 | 55 | #define pin_cylinder_reload p15 |
echo_piyo | 45:a32e8091901b | 56 | #define pin_sbdbt_pairing p12 |
echo_piyo | 45:a32e8091901b | 57 | #define pin_sbdbt_indicator p11 |
echo_piyo | 0:bf96e953cdb8 | 58 | |
echo_piyo | 45:a32e8091901b | 59 | DigitalOut led1(LED1); |
echo_piyo | 48:96b5f5ebdfb0 | 60 | DigitalOut led2(LED2); |
echo_piyo | 48:96b5f5ebdfb0 | 61 | DigitalOut led3(LED3); |
echo_piyo | 48:96b5f5ebdfb0 | 62 | DigitalOut led4(LED4); |
echo_piyo | 31:285c9898da03 | 63 | DigitalIn interrupt_cylinder_min(pin_interrupt_cylinder_min); |
echo_piyo | 0:bf96e953cdb8 | 64 | Serial pc(USBTX,USBRX); |
echo_piyo | 0:bf96e953cdb8 | 65 | RS422 rs422(rs422_tx, rs422_rx); |
echo_piyo | 45:a32e8091901b | 66 | Sbdbt sbdbt(sbdbt_tx, sbdbt_rx, pin_sbdbt_pairing); |
echo_piyo | 0:bf96e953cdb8 | 67 | Ticker output_timer; |
echo_piyo | 0:bf96e953cdb8 | 68 | Mecanum mecanum; |
echo_piyo | 0:bf96e953cdb8 | 69 | Bno055 bno055; |
echo_piyo | 2:d5b8f8e62923 | 70 | Position_pid yaw_pid; |
echo_piyo | 4:a6cc2f03e69b | 71 | Accel v1; |
echo_piyo | 4:a6cc2f03e69b | 72 | Accel v2; |
echo_piyo | 4:a6cc2f03e69b | 73 | Accel v3; |
echo_piyo | 4:a6cc2f03e69b | 74 | Accel v4; |
echo_piyo | 15:0fdf483769bf | 75 | Cylinder cylinder(pin_cylinder_on,pin_cylinder_off); |
echo_piyo | 26:3280d0300b04 | 76 | Cyclic sword; |
echo_piyo | 31:285c9898da03 | 77 | Cyclic cyclic_cylinder_position; |
echo_piyo | 31:285c9898da03 | 78 | DigitalIn interrupt_sholderright_min(pin_interrupt_sholderright_min); |
echo_piyo | 31:285c9898da03 | 79 | DigitalIn interrupt_sholderright_max(pin_interrupt_sholderright_max); |
echo_piyo | 31:285c9898da03 | 80 | DigitalIn interrupt_sholderleft_min(pin_interrupt_sholderleft_min); |
echo_piyo | 31:285c9898da03 | 81 | DigitalIn interrupt_sholderleft_max(pin_interrupt_sholderleft_max); |
echo_piyo | 35:5e1ad00f26fb | 82 | Encoder enc_cylinder(encoder_A,encoder_B); |
echo_piyo | 38:b071512af5ca | 83 | Cyclic cyclic_servo; |
echo_piyo | 42:63aedf71f4d1 | 84 | Cyclic_IO cylinder_reload(pin_cylinder_reload); |
echo_piyo | 35:5e1ad00f26fb | 85 | PwmOut servo(pin_servo); |
echo_piyo | 45:a32e8091901b | 86 | DigitalOut sbdbt_indigator(pin_sbdbt_indicator); |
echo_piyo | 50:e4e1f38d1bd5 | 87 | varEvent event; |
echo_piyo | 51:70d45b959d6b | 88 | varEvent cylinder_event; |
echo_piyo | 9:6486f4b3ac50 | 89 | |
echo_piyo | 0:bf96e953cdb8 | 90 | void setup(); |
echo_piyo | 0:bf96e953cdb8 | 91 | void output(); |
echo_piyo | 15:0fdf483769bf | 92 | void motor_cal(); |
echo_piyo | 16:e49df474e4c6 | 93 | void cylinder_cal(); |
echo_piyo | 10:04f2a82cfd89 | 94 | void boost(); |
echo_piyo | 12:1fec80ae8a2c | 95 | void cylinder_origin(); |
echo_piyo | 53:701dc7886fff | 96 | void firstmotion(); |
echo_piyo | 26:3280d0300b04 | 97 | void sword_cal(); |
echo_piyo | 35:5e1ad00f26fb | 98 | void servo_origin(); |
echo_piyo | 31:285c9898da03 | 99 | float shoulder_right_cal(); |
echo_piyo | 31:285c9898da03 | 100 | float shoulder_left_cal(); |
echo_piyo | 42:63aedf71f4d1 | 101 | |
echo_piyo | 39:6735743ac0f1 | 102 | //output |
echo_piyo | 2:d5b8f8e62923 | 103 | float yaw, target_yaw; |
echo_piyo | 39:6735743ac0f1 | 104 | //cylinder_origin |
echo_piyo | 38:b071512af5ca | 105 | int cylinder_origin_flag = 0; |
echo_piyo | 39:6735743ac0f1 | 106 | //cylinder |
echo_piyo | 39:6735743ac0f1 | 107 | float cylinder_pwm; |
echo_piyo | 39:6735743ac0f1 | 108 | int cylinder_pos_num = 0; |
echo_piyo | 42:63aedf71f4d1 | 109 | float cylinder_pos[3] = {0.0,90.0,325.0}; |
echo_piyo | 0:bf96e953cdb8 | 110 | |
echo_piyo | 0:bf96e953cdb8 | 111 | int main() |
echo_piyo | 0:bf96e953cdb8 | 112 | { |
echo_piyo | 0:bf96e953cdb8 | 113 | setup(); |
echo_piyo | 2:d5b8f8e62923 | 114 | while(1) { |
echo_piyo | 48:96b5f5ebdfb0 | 115 | led1 = interrupt_sholderleft_max; |
echo_piyo | 48:96b5f5ebdfb0 | 116 | led2 = interrupt_sholderleft_min; |
echo_piyo | 48:96b5f5ebdfb0 | 117 | led3 = interrupt_sholderright_max; |
echo_piyo | 48:96b5f5ebdfb0 | 118 | led4 = interrupt_sholderright_min; |
echo_piyo | 50:e4e1f38d1bd5 | 119 | |
echo_piyo | 50:e4e1f38d1bd5 | 120 | event.input(sbdbt.left); |
echo_piyo | 51:70d45b959d6b | 121 | pc.printf("riseState %d : fallState %d\r\n",event.getRise(),event.getFall()); |
echo_piyo | 0:bf96e953cdb8 | 122 | } |
echo_piyo | 0:bf96e953cdb8 | 123 | } |
echo_piyo | 0:bf96e953cdb8 | 124 | |
echo_piyo | 0:bf96e953cdb8 | 125 | void setup() |
echo_piyo | 0:bf96e953cdb8 | 126 | { |
echo_piyo | 40:2d6888448ab2 | 127 | wait(2.0); |
echo_piyo | 19:76a387e4bcf6 | 128 | bno055.begin(); |
echo_piyo | 40:2d6888448ab2 | 129 | wait(1.0); |
echo_piyo | 19:76a387e4bcf6 | 130 | bno055.firstRead(); |
echo_piyo | 0:bf96e953cdb8 | 131 | pc.baud(pc_baud); |
echo_piyo | 0:bf96e953cdb8 | 132 | sbdbt.begin(sbdbt_baud); |
echo_piyo | 0:bf96e953cdb8 | 133 | rs422.begin(rs422_baud); |
echo_piyo | 53:701dc7886fff | 134 | firstmotion(); |
echo_piyo | 49:b041c815c063 | 135 | cylinder_pos_num = 2; //セットアップタイムでの初期装填のため |
echo_piyo | 0:bf96e953cdb8 | 136 | output_timer.attach(&output, output_period); |
echo_piyo | 2:d5b8f8e62923 | 137 | yaw_pid.setup(yaw_Kp, yaw_Ki, yaw_Kd); |
echo_piyo | 39:6735743ac0f1 | 138 | mecanum.setupdeg(bno055.getYawRad()); //基盤が前後逆の場合+180 |
echo_piyo | 4:a6cc2f03e69b | 139 | v1.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 140 | v2.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 141 | v3.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 142 | v4.setup(acceleration,output_period); |
echo_piyo | 31:285c9898da03 | 143 | enc_cylinder.setup(100); |
echo_piyo | 13:dfae731e239f | 144 | enc_cylinder.set_parameter(enc_Kp,enc_Ki,enc_Kd); |
echo_piyo | 35:5e1ad00f26fb | 145 | servo.period(0.020); |
echo_piyo | 12:1fec80ae8a2c | 146 | } |
echo_piyo | 12:1fec80ae8a2c | 147 | |
echo_piyo | 36:dca1081c19b3 | 148 | //Sword |
echo_piyo | 35:5e1ad00f26fb | 149 | float shoulder_right_cal() |
echo_piyo | 15:0fdf483769bf | 150 | { |
echo_piyo | 40:2d6888448ab2 | 151 | if(interrupt_sholderright_max==0&&sbdbt.sankaku==1) { |
echo_piyo | 31:285c9898da03 | 152 | return 0.0; |
echo_piyo | 31:285c9898da03 | 153 | } |
echo_piyo | 40:2d6888448ab2 | 154 | if(interrupt_sholderright_min==0&&sbdbt.batu==1) { |
echo_piyo | 33:64fd1bd83bac | 155 | return 0.0; |
echo_piyo | 31:285c9898da03 | 156 | } |
echo_piyo | 31:285c9898da03 | 157 | return (-sbdbt.sankaku*0.8+sbdbt.batu*0.8); |
echo_piyo | 31:285c9898da03 | 158 | } |
echo_piyo | 31:285c9898da03 | 159 | |
echo_piyo | 35:5e1ad00f26fb | 160 | float shoulder_left_cal() |
echo_piyo | 35:5e1ad00f26fb | 161 | { |
echo_piyo | 40:2d6888448ab2 | 162 | if(interrupt_sholderleft_max==0&&sbdbt.sankaku==1) { |
echo_piyo | 31:285c9898da03 | 163 | return 0.0; |
echo_piyo | 31:285c9898da03 | 164 | } |
echo_piyo | 40:2d6888448ab2 | 165 | if(interrupt_sholderleft_min==0&&sbdbt.batu==1) { |
echo_piyo | 35:5e1ad00f26fb | 166 | return 0.0; |
echo_piyo | 31:285c9898da03 | 167 | } |
echo_piyo | 40:2d6888448ab2 | 168 | return (-sbdbt.sankaku*0.8+sbdbt.batu*0.8); |
echo_piyo | 31:285c9898da03 | 169 | } |
echo_piyo | 31:285c9898da03 | 170 | void sword_cal() |
echo_piyo | 31:285c9898da03 | 171 | { |
echo_piyo | 26:3280d0300b04 | 172 | sword.cyclic(sbdbt.maru); |
echo_piyo | 17:5c4718c603dc | 173 | } |
echo_piyo | 15:0fdf483769bf | 174 | |
echo_piyo | 36:dca1081c19b3 | 175 | //cylinder |
echo_piyo | 53:701dc7886fff | 176 | void firstmotion() |
echo_piyo | 31:285c9898da03 | 177 | { |
echo_piyo | 53:701dc7886fff | 178 | while(interrupt_cylinder_min == 1 || interrupt_sholderleft_max == 1 || interrupt_sholderright_max == 1){ |
echo_piyo | 53:701dc7886fff | 179 | float cylinder = 0.0; |
echo_piyo | 53:701dc7886fff | 180 | float sholderL = 0.0; |
echo_piyo | 53:701dc7886fff | 181 | float sholderR = 0.0; |
echo_piyo | 53:701dc7886fff | 182 | if(interrupt_cylinder_min == 1){ |
echo_piyo | 53:701dc7886fff | 183 | cylinder = 2.0; |
echo_piyo | 53:701dc7886fff | 184 | }else{ |
echo_piyo | 53:701dc7886fff | 185 | cylinder = 0.0; |
echo_piyo | 53:701dc7886fff | 186 | } |
echo_piyo | 53:701dc7886fff | 187 | if(interrupt_sholderright_max == 1){ |
echo_piyo | 53:701dc7886fff | 188 | sholderR = -2.0; |
echo_piyo | 53:701dc7886fff | 189 | }else{ |
echo_piyo | 53:701dc7886fff | 190 | sholderR = 0.0; |
echo_piyo | 53:701dc7886fff | 191 | } |
echo_piyo | 53:701dc7886fff | 192 | if(interrupt_sholderleft_max == 1){ |
echo_piyo | 53:701dc7886fff | 193 | sholderL = 2.0; |
echo_piyo | 53:701dc7886fff | 194 | }else{ |
echo_piyo | 53:701dc7886fff | 195 | sholderL = 0.0; |
echo_piyo | 53:701dc7886fff | 196 | } |
echo_piyo | 53:701dc7886fff | 197 | rs422.put(5, cylinder, 0.0); |
echo_piyo | 53:701dc7886fff | 198 | rs422.put(6, sholderR, sholderL); |
echo_piyo | 12:1fec80ae8a2c | 199 | } |
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 | 19:76a387e4bcf6 | 215 | void cylinder_cal() |
echo_piyo | 31:285c9898da03 | 216 | { |
echo_piyo | 31:285c9898da03 | 217 | cylinder.cyclic(sbdbt.shikaku); //cylinder ON/OFF |
echo_piyo | 51:70d45b959d6b | 218 | |
echo_piyo | 51:70d45b959d6b | 219 | cylinder_event.input(sbdbt.right); |
echo_piyo | 51:70d45b959d6b | 220 | if(cylinder_event.getRise()) { //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 | 50:e4e1f38d1bd5 | 227 | enc_cylinder.cal((float)cylinder_pos[cylinder_pos_num],output_period); //set cylinder_tergetPos |
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 | 19:76a387e4bcf6 | 230 | } |
echo_piyo | 38:b071512af5ca | 231 | |
echo_piyo | 45:a32e8091901b | 232 | void servo_max() |
echo_piyo | 45:a32e8091901b | 233 | { |
echo_piyo | 45:a32e8091901b | 234 | servo.pulsewidth(0.0022); |
echo_piyo | 35:5e1ad00f26fb | 235 | } |
echo_piyo | 38:b071512af5ca | 236 | void servo_min() |
echo_piyo | 35:5e1ad00f26fb | 237 | { |
echo_piyo | 35:5e1ad00f26fb | 238 | servo.pulsewidth(0.0010); |
echo_piyo | 38:b071512af5ca | 239 | } |
echo_piyo | 45:a32e8091901b | 240 | void servo_out() |
echo_piyo | 45:a32e8091901b | 241 | { |
echo_piyo | 39:6735743ac0f1 | 242 | cyclic_servo.cyclic(sbdbt.down); //setServoControl |
echo_piyo | 45:a32e8091901b | 243 | if(cyclic_servo.getState()==0) { |
echo_piyo | 39:6735743ac0f1 | 244 | servo_min(); |
echo_piyo | 45:a32e8091901b | 245 | } else if(cyclic_servo.getState()==1) { |
echo_piyo | 39:6735743ac0f1 | 246 | servo_max(); |
echo_piyo | 38:b071512af5ca | 247 | } |
echo_piyo | 35:5e1ad00f26fb | 248 | } |
echo_piyo | 35:5e1ad00f26fb | 249 | |
echo_piyo | 36:dca1081c19b3 | 250 | |
echo_piyo | 36:dca1081c19b3 | 251 | //boost |
echo_piyo | 31:285c9898da03 | 252 | void boost() |
echo_piyo | 31:285c9898da03 | 253 | { |
echo_piyo | 31:285c9898da03 | 254 | if(sbdbt.r2) { |
echo_piyo | 10:04f2a82cfd89 | 255 | mecanum.boost_forward(); |
echo_piyo | 10:04f2a82cfd89 | 256 | } |
echo_piyo | 31:285c9898da03 | 257 | if(sbdbt.l2) { |
echo_piyo | 10:04f2a82cfd89 | 258 | mecanum.boost_back(); |
echo_piyo | 10:04f2a82cfd89 | 259 | } |
echo_piyo | 26:3280d0300b04 | 260 | /* |
echo_piyo | 10:04f2a82cfd89 | 261 | if(sbdbt.shikaku) { |
echo_piyo | 10:04f2a82cfd89 | 262 | mecanum.boost_left(); |
echo_piyo | 10:04f2a82cfd89 | 263 | } |
echo_piyo | 10:04f2a82cfd89 | 264 | if(sbdbt.maru) { |
echo_piyo | 10:04f2a82cfd89 | 265 | mecanum.boost_right(); |
echo_piyo | 10:04f2a82cfd89 | 266 | } |
echo_piyo | 26:3280d0300b04 | 267 | */ |
echo_piyo | 10:04f2a82cfd89 | 268 | } |
echo_piyo | 10:04f2a82cfd89 | 269 | |
echo_piyo | 36:dca1081c19b3 | 270 | //mecanum |
echo_piyo | 15:0fdf483769bf | 271 | void motor_cal() |
echo_piyo | 5:6efda58ff71b | 272 | { |
echo_piyo | 4:a6cc2f03e69b | 273 | yaw = bno055.getYawRad(); |
echo_piyo | 4:a6cc2f03e69b | 274 | target_yaw = yaw; |
echo_piyo | 4:a6cc2f03e69b | 275 | yaw_pid.cal(target_yaw, yaw, output_period); |
echo_piyo | 4:a6cc2f03e69b | 276 | mecanum.sbdbt_cal(sbdbt.left_x, sbdbt.left_y, sbdbt.l1, sbdbt.r1, yaw_pid.duty(), bno055.getYawRad()); |
echo_piyo | 5:6efda58ff71b | 277 | // 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 | 278 | } |
echo_piyo | 35:5e1ad00f26fb | 279 | void output() |
echo_piyo | 35:5e1ad00f26fb | 280 | { |
echo_piyo | 35:5e1ad00f26fb | 281 | motor_cal(); |
echo_piyo | 35:5e1ad00f26fb | 282 | cylinder_cal(); |
echo_piyo | 35:5e1ad00f26fb | 283 | sword_cal(); |
echo_piyo | 38:b071512af5ca | 284 | servo_out(); |
echo_piyo | 38:b071512af5ca | 285 | cylinder_origin(); |
echo_piyo | 35:5e1ad00f26fb | 286 | //boost(); |
echo_piyo | 45:a32e8091901b | 287 | |
echo_piyo | 48:96b5f5ebdfb0 | 288 | //led1 = sbdbt.get_pairingState(); |
echo_piyo | 45:a32e8091901b | 289 | sbdbt_indigator = sbdbt.get_pairingState(); |
echo_piyo | 45:a32e8091901b | 290 | |
echo_piyo | 49:b041c815c063 | 291 | if(sbdbt.up)cylinder_origin_flag = 1; |
echo_piyo | 49:b041c815c063 | 292 | if(sbdbt.left)bno055.yaw_origin(); |
echo_piyo | 49:b041c815c063 | 293 | cylinder_reload.cyclic(sbdbt.down); |
echo_piyo | 45:a32e8091901b | 294 | |
echo_piyo | 35:5e1ad00f26fb | 295 | static int counter; |
echo_piyo | 53:701dc7886fff | 296 | static float mecanumV1, mecanumV2, mecanumV3, mecanumV4; |
echo_piyo | 35:5e1ad00f26fb | 297 | int id[nucleo_num] = {n1_id, n2_id, n3_id, n4_id, n5_id, n6_id}; |
echo_piyo | 45:a32e8091901b | 298 | |
echo_piyo | 45:a32e8091901b | 299 | //sbdbtがpairingしている場合のみ動作 |
echo_piyo | 45:a32e8091901b | 300 | if(sbdbt.get_pairingState()) { |
echo_piyo | 45:a32e8091901b | 301 | switch (counter) { |
echo_piyo | 45:a32e8091901b | 302 | case 0: |
echo_piyo | 53:701dc7886fff | 303 | rs422.put(id[counter], v1.duty(limitf(((mecanum.v1()*mecanum_power)+(sbdbt.right_y*0.8)),1.0,-1.0)), v3.duty(limitf(((mecanum.v3()*mecanum_power)+(sbdbt.right_y*0.8)),1.0,-1.0))); |
echo_piyo | 45:a32e8091901b | 304 | counter++; |
echo_piyo | 45:a32e8091901b | 305 | break; |
echo_piyo | 45:a32e8091901b | 306 | case 1: |
echo_piyo | 45:a32e8091901b | 307 | //.duty(<cal>*<powerControle>+(<boost>*0.5)) |
echo_piyo | 53:701dc7886fff | 308 | rs422.put(id[counter], v2.duty(limitf(((mecanum.v2()*mecanum_power)-(sbdbt.right_y*0.8)),1.0,-1.0)), v4.duty(limitf(((mecanum.v4()*mecanum_power)-(sbdbt.right_y*0.8)),1.0,-1.0))); |
echo_piyo | 45:a32e8091901b | 309 | counter ++; |
echo_piyo | 45:a32e8091901b | 310 | break; |
echo_piyo | 45:a32e8091901b | 311 | case 2: |
echo_piyo | 53:701dc7886fff | 312 | rs422.put(id[counter], limitf((-1*enc_cylinder.duty_enableWidth(-5.0,5.0)),1.0,-1.0), 0.0); |
echo_piyo | 45:a32e8091901b | 313 | counter ++; |
echo_piyo | 45:a32e8091901b | 314 | break; |
echo_piyo | 45:a32e8091901b | 315 | case 3: |
echo_piyo | 53:701dc7886fff | 316 | rs422.put(id[counter], limitf((-1*shoulder_right_cal()*sholder_power),1.0,-1.0), limitf((shoulder_left_cal()*sholder_power),1.0,-1.0)); |
echo_piyo | 45:a32e8091901b | 317 | counter ++; |
echo_piyo | 45:a32e8091901b | 318 | break; |
echo_piyo | 45:a32e8091901b | 319 | case 4: |
echo_piyo | 53:701dc7886fff | 320 | rs422.put(id[counter], limitf(((float)sword.getState()*sword_power),1.0,-1.0),0.0); |
echo_piyo | 45:a32e8091901b | 321 | counter = 0; |
echo_piyo | 45:a32e8091901b | 322 | break; |
echo_piyo | 45:a32e8091901b | 323 | default: |
echo_piyo | 45:a32e8091901b | 324 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 325 | } |
echo_piyo | 45:a32e8091901b | 326 | }else{ |
echo_piyo | 48:96b5f5ebdfb0 | 327 | switch (counter) { |
echo_piyo | 48:96b5f5ebdfb0 | 328 | case 0: |
echo_piyo | 48:96b5f5ebdfb0 | 329 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 330 | counter++; |
echo_piyo | 48:96b5f5ebdfb0 | 331 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 332 | case 1: |
echo_piyo | 48:96b5f5ebdfb0 | 333 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 334 | counter ++; |
echo_piyo | 48:96b5f5ebdfb0 | 335 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 336 | case 2: |
echo_piyo | 48:96b5f5ebdfb0 | 337 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 338 | counter ++; |
echo_piyo | 48:96b5f5ebdfb0 | 339 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 340 | case 3: |
echo_piyo | 48:96b5f5ebdfb0 | 341 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 342 | counter ++; |
echo_piyo | 48:96b5f5ebdfb0 | 343 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 344 | case 4: |
echo_piyo | 48:96b5f5ebdfb0 | 345 | rs422.put(id[counter],0.0,0.0); |
echo_piyo | 48:96b5f5ebdfb0 | 346 | counter = 0; |
echo_piyo | 48:96b5f5ebdfb0 | 347 | break; |
echo_piyo | 48:96b5f5ebdfb0 | 348 | default: |
echo_piyo | 48:96b5f5ebdfb0 | 349 | break; |
echo_piyo | 45:a32e8091901b | 350 | } |
echo_piyo | 45:a32e8091901b | 351 | } |
echo_piyo | 14:aac2f18f6779 | 352 | } |