ライブラリ化を行った後
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@8:3b7530174f8a, 2017-07-05 (annotated)
- Committer:
- echo_piyo
- Date:
- Wed Jul 05 11:31:29 2017 +0000
- Revision:
- 8:3b7530174f8a
- Parent:
- 5:6efda58ff71b
- Child:
- 9:6486f4b3ac50
test
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 | 0:bf96e953cdb8 | 12 | |
echo_piyo | 0:bf96e953cdb8 | 13 | #define pc_baud 460800 |
echo_piyo | 0:bf96e953cdb8 | 14 | #define sbdbt_tx p13 |
echo_piyo | 0:bf96e953cdb8 | 15 | #define sbdbt_rx p14 |
echo_piyo | 0:bf96e953cdb8 | 16 | #define sbdbt_baud 115200 |
echo_piyo | 0:bf96e953cdb8 | 17 | #define rs422_tx p28 |
echo_piyo | 0:bf96e953cdb8 | 18 | #define rs422_rx p27 |
echo_piyo | 0:bf96e953cdb8 | 19 | #define rs422_baud 115200 |
echo_piyo | 3:9ef929639c4a | 20 | #define output_period 0.015 |
echo_piyo | 0:bf96e953cdb8 | 21 | #define nucleo_num 3 |
echo_piyo | 0:bf96e953cdb8 | 22 | #define pi 3.141592 |
echo_piyo | 0:bf96e953cdb8 | 23 | #define n1_id 3 |
echo_piyo | 0:bf96e953cdb8 | 24 | #define n2_id 4 |
echo_piyo | 0:bf96e953cdb8 | 25 | #define n3_id 0 |
echo_piyo | 5:6efda58ff71b | 26 | #define yaw_Kp 0.01 |
echo_piyo | 5:6efda58ff71b | 27 | #define yaw_Ki 0.01 |
echo_piyo | 5:6efda58ff71b | 28 | #define yaw_Kd 0.01 |
echo_piyo | 4:a6cc2f03e69b | 29 | #define acceleration 5 |
echo_piyo | 0:bf96e953cdb8 | 30 | |
echo_piyo | 0:bf96e953cdb8 | 31 | DigitalOut led(LED1); |
echo_piyo | 0:bf96e953cdb8 | 32 | Serial pc(USBTX,USBRX); |
echo_piyo | 0:bf96e953cdb8 | 33 | RS422 rs422(rs422_tx, rs422_rx); |
echo_piyo | 0:bf96e953cdb8 | 34 | Sbdbt sbdbt(sbdbt_tx, sbdbt_rx); |
echo_piyo | 0:bf96e953cdb8 | 35 | Ticker output_timer; |
echo_piyo | 0:bf96e953cdb8 | 36 | Mecanum mecanum; |
echo_piyo | 0:bf96e953cdb8 | 37 | Bno055 bno055; |
echo_piyo | 2:d5b8f8e62923 | 38 | Position_pid yaw_pid; |
echo_piyo | 4:a6cc2f03e69b | 39 | Accel v1; |
echo_piyo | 4:a6cc2f03e69b | 40 | Accel v2; |
echo_piyo | 4:a6cc2f03e69b | 41 | Accel v3; |
echo_piyo | 4:a6cc2f03e69b | 42 | Accel v4; |
echo_piyo | 0:bf96e953cdb8 | 43 | |
echo_piyo | 0:bf96e953cdb8 | 44 | void setup(); |
echo_piyo | 0:bf96e953cdb8 | 45 | void output(); |
echo_piyo | 0:bf96e953cdb8 | 46 | void put_output(); |
echo_piyo | 2:d5b8f8e62923 | 47 | float yaw, target_yaw; |
echo_piyo | 0:bf96e953cdb8 | 48 | |
echo_piyo | 0:bf96e953cdb8 | 49 | int main() |
echo_piyo | 0:bf96e953cdb8 | 50 | { |
echo_piyo | 0:bf96e953cdb8 | 51 | setup(); |
echo_piyo | 2:d5b8f8e62923 | 52 | while(1) { |
echo_piyo | 0:bf96e953cdb8 | 53 | } |
echo_piyo | 0:bf96e953cdb8 | 54 | } |
echo_piyo | 0:bf96e953cdb8 | 55 | |
echo_piyo | 0:bf96e953cdb8 | 56 | void setup() |
echo_piyo | 0:bf96e953cdb8 | 57 | { |
echo_piyo | 1:2d878962e6ea | 58 | wait(1); |
echo_piyo | 0:bf96e953cdb8 | 59 | bno055.begin(); |
echo_piyo | 0:bf96e953cdb8 | 60 | wait(1); |
echo_piyo | 0:bf96e953cdb8 | 61 | bno055.firstRead(); |
echo_piyo | 0:bf96e953cdb8 | 62 | pc.baud(pc_baud); |
echo_piyo | 0:bf96e953cdb8 | 63 | sbdbt.begin(sbdbt_baud); |
echo_piyo | 0:bf96e953cdb8 | 64 | rs422.begin(rs422_baud); |
echo_piyo | 0:bf96e953cdb8 | 65 | output_timer.attach(&output, output_period); |
echo_piyo | 2:d5b8f8e62923 | 66 | yaw_pid.setup(yaw_Kp, yaw_Ki, yaw_Kd); |
echo_piyo | 0:bf96e953cdb8 | 67 | mecanum.setupdeg(bno055.getYawRad()); |
echo_piyo | 4:a6cc2f03e69b | 68 | v1.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 69 | v2.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 70 | v3.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 71 | v4.setup(acceleration,output_period); |
echo_piyo | 0:bf96e953cdb8 | 72 | } |
echo_piyo | 0:bf96e953cdb8 | 73 | |
echo_piyo | 5:6efda58ff71b | 74 | void put_output() |
echo_piyo | 5:6efda58ff71b | 75 | { |
echo_piyo | 4:a6cc2f03e69b | 76 | yaw = bno055.getYawRad(); |
echo_piyo | 4:a6cc2f03e69b | 77 | target_yaw = yaw; |
echo_piyo | 4:a6cc2f03e69b | 78 | yaw_pid.cal(target_yaw, yaw, output_period); |
echo_piyo | 4:a6cc2f03e69b | 79 | mecanum.sbdbt_cal(sbdbt.left_x, sbdbt.left_y, sbdbt.l1, sbdbt.r1, yaw_pid.duty(), bno055.getYawRad()); |
echo_piyo | 5:6efda58ff71b | 80 | // 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 | 0:bf96e953cdb8 | 81 | } |
echo_piyo | 0:bf96e953cdb8 | 82 | |
echo_piyo | 0:bf96e953cdb8 | 83 | void output() |
echo_piyo | 0:bf96e953cdb8 | 84 | { |
echo_piyo | 4:a6cc2f03e69b | 85 | put_output(); |
echo_piyo | 4:a6cc2f03e69b | 86 | |
echo_piyo | 0:bf96e953cdb8 | 87 | static int counter; |
echo_piyo | 0:bf96e953cdb8 | 88 | int id[nucleo_num] = {n1_id, n2_id, n3_id}; |
echo_piyo | 0:bf96e953cdb8 | 89 | |
echo_piyo | 5:6efda58ff71b | 90 | if(sbdbt.batu) { |
echo_piyo | 5:6efda58ff71b | 91 | mecanum.boost(); |
echo_piyo | 5:6efda58ff71b | 92 | } |
echo_piyo | 5:6efda58ff71b | 93 | |
echo_piyo | 0:bf96e953cdb8 | 94 | switch (counter) { |
echo_piyo | 0:bf96e953cdb8 | 95 | case 0: |
echo_piyo | 4:a6cc2f03e69b | 96 | rs422.put(id[counter], v1.duty(mecanum.v1()), v3.duty(mecanum.v3())); |
echo_piyo | 0:bf96e953cdb8 | 97 | counter++; |
echo_piyo | 0:bf96e953cdb8 | 98 | break; |
echo_piyo | 0:bf96e953cdb8 | 99 | case 1: |
echo_piyo | 4:a6cc2f03e69b | 100 | rs422.put(id[counter], v2.duty(mecanum.v2()), v4.duty(mecanum.v4())); |
echo_piyo | 0:bf96e953cdb8 | 101 | counter ++; |
echo_piyo | 0:bf96e953cdb8 | 102 | break; |
echo_piyo | 0:bf96e953cdb8 | 103 | case 2: |
echo_piyo | 0:bf96e953cdb8 | 104 | rs422.put(id[counter], 0.0, 0.0); |
echo_piyo | 0:bf96e953cdb8 | 105 | counter = 0; |
echo_piyo | 0:bf96e953cdb8 | 106 | break; |
echo_piyo | 0:bf96e953cdb8 | 107 | default: |
echo_piyo | 0:bf96e953cdb8 | 108 | break; |
echo_piyo | 0:bf96e953cdb8 | 109 | }; |
echo_piyo | 5:6efda58ff71b | 110 | } |
echo_piyo | 5:6efda58ff71b | 111 |