2017_CatchRobo_f103rb
Fork of 2017_CatchRobo_f103rb by
2017_CatchRobo_f103rb.cpp@2:c0303b37bc3a, 2017-08-12 (annotated)
- Committer:
- Abe_t
- Date:
- Sat Aug 12 15:00:08 2017 +0000
- Revision:
- 2:c0303b37bc3a
- Parent:
- 1:a9850521074c
- Child:
- 7:06a366a57be8
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Abe_t | 1:a9850521074c | 1 | //送信側マイコン nucleo_f103rb |
Abe_t | 1:a9850521074c | 2 | |
Abe_t | 1:a9850521074c | 3 | #include "mbed.h" |
Abe_t | 1:a9850521074c | 4 | #include "servo_motor.h" |
Abe_t | 1:a9850521074c | 5 | #include "ps3_controller.h" |
Abe_t | 1:a9850521074c | 6 | #include "dc_motor_1.h" |
Abe_t | 1:a9850521074c | 7 | #include "rotary_encoder.h" |
Abe_t | 1:a9850521074c | 8 | #include "CANnucleo.h" |
Abe_t | 1:a9850521074c | 9 | #include "servo_motor_270.h" |
Abe_t | 1:a9850521074c | 10 | |
Abe_t | 1:a9850521074c | 11 | |
Abe_t | 1:a9850521074c | 12 | /***初期化関数**************************************/ |
Abe_t | 1:a9850521074c | 13 | |
Abe_t | 1:a9850521074c | 14 | Serial pc(USBTX,USBRX); |
Abe_t | 1:a9850521074c | 15 | ps3_cont ps3(PC_10,PC_11); |
Abe_t | 1:a9850521074c | 16 | Timer system_cycle; |
Abe_t | 1:a9850521074c | 17 | CAN* can; |
Abe_t | 1:a9850521074c | 18 | CANMessage txMsg; |
Abe_t | 1:a9850521074c | 19 | |
Abe_t | 1:a9850521074c | 20 | |
Abe_t | 1:a9850521074c | 21 | //センサー類 |
Abe_t | 1:a9850521074c | 22 | rotary_encoder enco1(PC_0,PC_3,NC,500,rotary_encoder::X4_ENCODING); |
Abe_t | 1:a9850521074c | 23 | rotary_encoder enco2(PA_13,PA_14,NC,500,rotary_encoder::X4_ENCODING); |
Abe_t | 1:a9850521074c | 24 | rotary_encoder enco3(PD_2,PC_15,NC,500,rotary_encoder::X4_ENCODING); |
Abe_t | 1:a9850521074c | 25 | |
Abe_t | 1:a9850521074c | 26 | //アクチュエータ類 |
Abe_t | 1:a9850521074c | 27 | dc_motor_1 motor1(A3,A2,1); //tiemr_3_3 |
Abe_t | 1:a9850521074c | 28 | dc_motor_1 motor2(D4,A4,1); //timer_3_2 |
Abe_t | 1:a9850521074c | 29 | dc_motor_1 motor3(D5,A0,1); //timer_3_1 |
Abe_t | 1:a9850521074c | 30 | |
Abe_t | 1:a9850521074c | 31 | ServoMotor_270 servo1(PB_13); //timer_1_1N |
Abe_t | 1:a9850521074c | 32 | |
Abe_t | 1:a9850521074c | 33 | DigitalOut LED[3]={D12,D11,D10}; |
Abe_t | 1:a9850521074c | 34 | DigitalOut button[2]={D9,D8}; |
Abe_t | 1:a9850521074c | 35 | |
Abe_t | 1:a9850521074c | 36 | DigitalOut buzzer(PC_8); |
Abe_t | 1:a9850521074c | 37 | |
Abe_t | 1:a9850521074c | 38 | /********グローバル変数******************************/ |
Abe_t | 1:a9850521074c | 39 | |
Abe_t | 1:a9850521074c | 40 | const unsigned int TX_ID = 0x101; |
Abe_t | 1:a9850521074c | 41 | uint8_t counter = 0; |
Abe_t | 1:a9850521074c | 42 | |
Abe_t | 1:a9850521074c | 43 | /**************************************************/ |
Abe_t | 1:a9850521074c | 44 | |
Abe_t | 1:a9850521074c | 45 | void print_Msg(CANMessage &msg){ |
Abe_t | 1:a9850521074c | 46 | pc.printf("sent_date ="); |
Abe_t | 1:a9850521074c | 47 | for(int i=0 ; i<msg.len ; i++){ |
Abe_t | 1:a9850521074c | 48 | pc.printf("0x%.2X\t",msg.data[i]); |
Abe_t | 1:a9850521074c | 49 | } |
Abe_t | 1:a9850521074c | 50 | } |
Abe_t | 1:a9850521074c | 51 | |
Abe_t | 1:a9850521074c | 52 | int main() |
Abe_t | 1:a9850521074c | 53 | { |
Abe_t | 1:a9850521074c | 54 | pc.baud(9600); |
Abe_t | 1:a9850521074c | 55 | can = new CAN(PA_11,PA_12); |
Abe_t | 1:a9850521074c | 56 | can -> frequency(1000000); |
Abe_t | 1:a9850521074c | 57 | system_cycle.start(); |
Abe_t | 1:a9850521074c | 58 | pc.printf("program_start!!"); |
Abe_t | 1:a9850521074c | 59 | |
Abe_t | 1:a9850521074c | 60 | while(1){ |
Abe_t | 1:a9850521074c | 61 | while( (system_cycle.read_ms() >= 30) ){ |
Abe_t | 1:a9850521074c | 62 | |
Abe_t | 1:a9850521074c | 63 | txMsg.clear(); |
Abe_t | 1:a9850521074c | 64 | txMsg.id = TX_ID; |
Abe_t | 1:a9850521074c | 65 | txMsg << counter; |
Abe_t | 1:a9850521074c | 66 | |
Abe_t | 1:a9850521074c | 67 | if(can->write(txMsg)){ |
Abe_t | 1:a9850521074c | 68 | print_Msg(txMsg); |
Abe_t | 1:a9850521074c | 69 | } |
Abe_t | 1:a9850521074c | 70 | else{ |
Abe_t | 1:a9850521074c | 71 | pc.printf("sent_error/r/n"); |
Abe_t | 1:a9850521074c | 72 | } |
Abe_t | 1:a9850521074c | 73 | |
Abe_t | 1:a9850521074c | 74 | if( ps3.getbutton(square)==1){ |
Abe_t | 1:a9850521074c | 75 | motor1.drive(20.0); |
Abe_t | 1:a9850521074c | 76 | LED[0].write(1); |
Abe_t | 1:a9850521074c | 77 | } |
Abe_t | 1:a9850521074c | 78 | else if( ps3.getbutton(triangle)==1){ |
Abe_t | 1:a9850521074c | 79 | motor2.drive(20.0); |
Abe_t | 1:a9850521074c | 80 | LED[1].write(1); |
Abe_t | 1:a9850521074c | 81 | } |
Abe_t | 1:a9850521074c | 82 | else if( ps3.getbutton(circle)==1){ |
Abe_t | 1:a9850521074c | 83 | motor3.drive(20.0); |
Abe_t | 1:a9850521074c | 84 | LED[2].write(1); |
Abe_t | 1:a9850521074c | 85 | } |
Abe_t | 1:a9850521074c | 86 | else if( ps3.getbutton(left)==1){ |
Abe_t | 1:a9850521074c | 87 | servo1.weak_condition(); |
Abe_t | 1:a9850521074c | 88 | } |
Abe_t | 1:a9850521074c | 89 | else if( ps3.getbutton(right)==1){ |
Abe_t | 1:a9850521074c | 90 | servo1.rot(270.0); |
Abe_t | 1:a9850521074c | 91 | } |
Abe_t | 1:a9850521074c | 92 | else if( ps3.getbutton(L1)==1){ |
Abe_t | 1:a9850521074c | 93 | buzzer.write(1); |
Abe_t | 1:a9850521074c | 94 | } |
Abe_t | 1:a9850521074c | 95 | else if(ps3.getbutton(L2)==1){ |
Abe_t | 1:a9850521074c | 96 | counter = 1; |
Abe_t | 1:a9850521074c | 97 | } |
Abe_t | 1:a9850521074c | 98 | else if(ps3.getbutton(R2)==1){ |
Abe_t | 1:a9850521074c | 99 | counter = 2; |
Abe_t | 1:a9850521074c | 100 | } |
Abe_t | 1:a9850521074c | 101 | else if(ps3.getbutton(up)==1){ |
Abe_t | 1:a9850521074c | 102 | counter = 3; |
Abe_t | 1:a9850521074c | 103 | } |
Abe_t | 1:a9850521074c | 104 | else if(ps3.getbutton(under)==1){ |
Abe_t | 1:a9850521074c | 105 | counter = 4; |
Abe_t | 1:a9850521074c | 106 | } |
Abe_t | 1:a9850521074c | 107 | else if(button[0].read() == 1){ |
Abe_t | 1:a9850521074c | 108 | LED[0].write(1); |
Abe_t | 1:a9850521074c | 109 | } |
Abe_t | 1:a9850521074c | 110 | else if(button[1].read() == 1){ |
Abe_t | 1:a9850521074c | 111 | LED[1].write(1); |
Abe_t | 1:a9850521074c | 112 | } |
Abe_t | 1:a9850521074c | 113 | |
Abe_t | 1:a9850521074c | 114 | else{ |
Abe_t | 1:a9850521074c | 115 | counter = 0; |
Abe_t | 1:a9850521074c | 116 | LED[1].write(0); |
Abe_t | 1:a9850521074c | 117 | LED[2].write(0); |
Abe_t | 1:a9850521074c | 118 | LED[0].write(0); |
Abe_t | 1:a9850521074c | 119 | buzzer.write(0); |
Abe_t | 1:a9850521074c | 120 | servo1.rot(135.0); |
Abe_t | 1:a9850521074c | 121 | motor1.drive(0.0); |
Abe_t | 1:a9850521074c | 122 | motor2.drive(0.0); |
Abe_t | 1:a9850521074c | 123 | motor3.drive(0.0); |
Abe_t | 1:a9850521074c | 124 | } |
Abe_t | 1:a9850521074c | 125 | |
Abe_t | 1:a9850521074c | 126 | pc.printf("%f\t %f\t %f\t %d\t \r\n",enco1.getDeg(),enco2.getDeg(),enco3.getDeg(),buzzer.read()); |
Abe_t | 1:a9850521074c | 127 | system_cycle.reset(); |
Abe_t | 1:a9850521074c | 128 | }//(while system_cycle ) |
Abe_t | 1:a9850521074c | 129 | if( ps3.getbutton(cross)==1){break;} |
Abe_t | 1:a9850521074c | 130 | }//(while) |
Abe_t | 1:a9850521074c | 131 | } |
Abe_t | 1:a9850521074c | 132 |