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