ライブラリ化を行った後
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@11:bbd999225791, 2017-07-16 (annotated)
- Committer:
- echo_piyo
- Date:
- Sun Jul 16 04:11:32 2017 +0000
- Revision:
- 11:bbd999225791
- Parent:
- 9:6486f4b3ac50
(??)????????180???????
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 | 9:6486f4b3ac50 | 44 | |
echo_piyo | 0:bf96e953cdb8 | 45 | void setup(); |
echo_piyo | 0:bf96e953cdb8 | 46 | void output(); |
echo_piyo | 0:bf96e953cdb8 | 47 | void put_output(); |
echo_piyo | 2:d5b8f8e62923 | 48 | float yaw, target_yaw; |
echo_piyo | 0:bf96e953cdb8 | 49 | |
echo_piyo | 0:bf96e953cdb8 | 50 | int main() |
echo_piyo | 0:bf96e953cdb8 | 51 | { |
echo_piyo | 0:bf96e953cdb8 | 52 | setup(); |
echo_piyo | 2:d5b8f8e62923 | 53 | while(1) { |
echo_piyo | 0:bf96e953cdb8 | 54 | } |
echo_piyo | 0:bf96e953cdb8 | 55 | } |
echo_piyo | 0:bf96e953cdb8 | 56 | |
echo_piyo | 0:bf96e953cdb8 | 57 | void setup() |
echo_piyo | 0:bf96e953cdb8 | 58 | { |
echo_piyo | 1:2d878962e6ea | 59 | wait(1); |
echo_piyo | 0:bf96e953cdb8 | 60 | bno055.begin(); |
echo_piyo | 0:bf96e953cdb8 | 61 | wait(1); |
echo_piyo | 0:bf96e953cdb8 | 62 | bno055.firstRead(); |
echo_piyo | 0:bf96e953cdb8 | 63 | pc.baud(pc_baud); |
echo_piyo | 0:bf96e953cdb8 | 64 | sbdbt.begin(sbdbt_baud); |
echo_piyo | 0:bf96e953cdb8 | 65 | rs422.begin(rs422_baud); |
echo_piyo | 0:bf96e953cdb8 | 66 | output_timer.attach(&output, output_period); |
echo_piyo | 2:d5b8f8e62923 | 67 | yaw_pid.setup(yaw_Kp, yaw_Ki, yaw_Kd); |
echo_piyo | 11:bbd999225791 | 68 | mecanum.setupdeg(bno055.getYawRad()+180); |
echo_piyo | 4:a6cc2f03e69b | 69 | v1.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 70 | v2.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 71 | v3.setup(acceleration,output_period); |
echo_piyo | 4:a6cc2f03e69b | 72 | v4.setup(acceleration,output_period); |
echo_piyo | 0:bf96e953cdb8 | 73 | } |
echo_piyo | 0:bf96e953cdb8 | 74 | |
echo_piyo | 5:6efda58ff71b | 75 | void put_output() |
echo_piyo | 5:6efda58ff71b | 76 | { |
echo_piyo | 4:a6cc2f03e69b | 77 | yaw = bno055.getYawRad(); |
echo_piyo | 4:a6cc2f03e69b | 78 | target_yaw = yaw; |
echo_piyo | 4:a6cc2f03e69b | 79 | yaw_pid.cal(target_yaw, yaw, output_period); |
echo_piyo | 4:a6cc2f03e69b | 80 | mecanum.sbdbt_cal(sbdbt.left_x, sbdbt.left_y, sbdbt.l1, sbdbt.r1, yaw_pid.duty(), bno055.getYawRad()); |
echo_piyo | 5:6efda58ff71b | 81 | // 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 | 82 | } |
echo_piyo | 0:bf96e953cdb8 | 83 | |
echo_piyo | 0:bf96e953cdb8 | 84 | void output() |
echo_piyo | 0:bf96e953cdb8 | 85 | { |
echo_piyo | 4:a6cc2f03e69b | 86 | put_output(); |
echo_piyo | 4:a6cc2f03e69b | 87 | |
echo_piyo | 0:bf96e953cdb8 | 88 | static int counter; |
echo_piyo | 0:bf96e953cdb8 | 89 | int id[nucleo_num] = {n1_id, n2_id, n3_id}; |
echo_piyo | 0:bf96e953cdb8 | 90 | |
echo_piyo | 5:6efda58ff71b | 91 | if(sbdbt.batu) { |
echo_piyo | 5:6efda58ff71b | 92 | mecanum.boost(); |
echo_piyo | 5:6efda58ff71b | 93 | } |
echo_piyo | 5:6efda58ff71b | 94 | |
echo_piyo | 0:bf96e953cdb8 | 95 | switch (counter) { |
echo_piyo | 0:bf96e953cdb8 | 96 | case 0: |
echo_piyo | 4:a6cc2f03e69b | 97 | rs422.put(id[counter], v1.duty(mecanum.v1()), v3.duty(mecanum.v3())); |
echo_piyo | 0:bf96e953cdb8 | 98 | counter++; |
echo_piyo | 0:bf96e953cdb8 | 99 | break; |
echo_piyo | 0:bf96e953cdb8 | 100 | case 1: |
echo_piyo | 4:a6cc2f03e69b | 101 | rs422.put(id[counter], v2.duty(mecanum.v2()), v4.duty(mecanum.v4())); |
echo_piyo | 0:bf96e953cdb8 | 102 | counter ++; |
echo_piyo | 0:bf96e953cdb8 | 103 | break; |
echo_piyo | 0:bf96e953cdb8 | 104 | case 2: |
echo_piyo | 0:bf96e953cdb8 | 105 | rs422.put(id[counter], 0.0, 0.0); |
echo_piyo | 0:bf96e953cdb8 | 106 | counter = 0; |
echo_piyo | 0:bf96e953cdb8 | 107 | break; |
echo_piyo | 0:bf96e953cdb8 | 108 | default: |
echo_piyo | 0:bf96e953cdb8 | 109 | break; |
echo_piyo | 0:bf96e953cdb8 | 110 | }; |
echo_piyo | 5:6efda58ff71b | 111 | } |
echo_piyo | 5:6efda58ff71b | 112 |