Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 2017_CatchRobo_f103rb by
2017_CatchRobo_f103rb.cpp@8:f0f551fa29d4, 2017-08-22 (annotated)
- Committer:
- Abe_t
- Date:
- Tue Aug 22 12:50:03 2017 +0000
- Revision:
- 8:f0f551fa29d4
- Parent:
- 7:06a366a57be8
????
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 | 8:f0f551fa29d4 | 22 | rotary_encoder enco1(PA_13,PA_14,NC,500,rotary_encoder::X4_ENCODING); |
| Abe_t | 8:f0f551fa29d4 | 23 | rotary_encoder enco2(PC_0,PC_3,NC,500,rotary_encoder::X4_ENCODING); |
| Abe_t | 8:f0f551fa29d4 | 24 | rotary_encoder enco3(PC_15,PD_2,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 | 8:f0f551fa29d4 | 54 | float init_deg1 = 180.0; |
| Abe_t | 8:f0f551fa29d4 | 55 | float init_deg2 = 0.0; |
| Abe_t | 8:f0f551fa29d4 | 56 | float deg1 = 180.0; |
| Abe_t | 8:f0f551fa29d4 | 57 | float deg2 = 0.0; |
| Abe_t | 8:f0f551fa29d4 | 58 | |
| Abe_t | 1:a9850521074c | 59 | pc.baud(9600); |
| Abe_t | 1:a9850521074c | 60 | can = new CAN(PA_11,PA_12); |
| Abe_t | 1:a9850521074c | 61 | can -> frequency(1000000); |
| Abe_t | 1:a9850521074c | 62 | system_cycle.start(); |
| Abe_t | 1:a9850521074c | 63 | pc.printf("program_start!!"); |
| Abe_t | 1:a9850521074c | 64 | |
| Abe_t | 1:a9850521074c | 65 | while(1){ |
| Abe_t | 7:06a366a57be8 | 66 | while( (system_cycle.read_ms() >= 20) ){ |
| Abe_t | 1:a9850521074c | 67 | |
| Abe_t | 1:a9850521074c | 68 | txMsg.clear(); |
| Abe_t | 1:a9850521074c | 69 | txMsg.id = TX_ID; |
| Abe_t | 1:a9850521074c | 70 | txMsg << counter; |
| Abe_t | 1:a9850521074c | 71 | |
| Abe_t | 1:a9850521074c | 72 | if(can->write(txMsg)){ |
| Abe_t | 1:a9850521074c | 73 | print_Msg(txMsg); |
| Abe_t | 1:a9850521074c | 74 | } |
| Abe_t | 1:a9850521074c | 75 | else{ |
| Abe_t | 1:a9850521074c | 76 | pc.printf("sent_error/r/n"); |
| Abe_t | 1:a9850521074c | 77 | } |
| Abe_t | 1:a9850521074c | 78 | |
| Abe_t | 1:a9850521074c | 79 | if( ps3.getbutton(square)==1){ |
| Abe_t | 1:a9850521074c | 80 | motor1.drive(20.0); |
| Abe_t | 1:a9850521074c | 81 | LED[0].write(1); |
| Abe_t | 1:a9850521074c | 82 | } |
| Abe_t | 1:a9850521074c | 83 | else if( ps3.getbutton(triangle)==1){ |
| Abe_t | 1:a9850521074c | 84 | motor2.drive(20.0); |
| Abe_t | 1:a9850521074c | 85 | LED[1].write(1); |
| Abe_t | 1:a9850521074c | 86 | } |
| Abe_t | 1:a9850521074c | 87 | else if( ps3.getbutton(circle)==1){ |
| Abe_t | 1:a9850521074c | 88 | motor3.drive(20.0); |
| Abe_t | 1:a9850521074c | 89 | LED[2].write(1); |
| Abe_t | 1:a9850521074c | 90 | } |
| Abe_t | 1:a9850521074c | 91 | else if( ps3.getbutton(left)==1){ |
| Abe_t | 1:a9850521074c | 92 | servo1.weak_condition(); |
| Abe_t | 1:a9850521074c | 93 | } |
| Abe_t | 1:a9850521074c | 94 | else if( ps3.getbutton(right)==1){ |
| Abe_t | 8:f0f551fa29d4 | 95 | servo1.rot(0.0); |
| Abe_t | 1:a9850521074c | 96 | } |
| Abe_t | 1:a9850521074c | 97 | else if( ps3.getbutton(L1)==1){ |
| Abe_t | 1:a9850521074c | 98 | buzzer.write(1); |
| Abe_t | 1:a9850521074c | 99 | } |
| Abe_t | 1:a9850521074c | 100 | else if(ps3.getbutton(L2)==1){ |
| Abe_t | 1:a9850521074c | 101 | counter = 1; |
| Abe_t | 1:a9850521074c | 102 | } |
| Abe_t | 1:a9850521074c | 103 | else if(ps3.getbutton(R2)==1){ |
| Abe_t | 1:a9850521074c | 104 | counter = 2; |
| Abe_t | 1:a9850521074c | 105 | } |
| Abe_t | 1:a9850521074c | 106 | else if(ps3.getbutton(up)==1){ |
| Abe_t | 1:a9850521074c | 107 | counter = 3; |
| Abe_t | 1:a9850521074c | 108 | } |
| Abe_t | 1:a9850521074c | 109 | else if(ps3.getbutton(under)==1){ |
| Abe_t | 1:a9850521074c | 110 | counter = 4; |
| Abe_t | 1:a9850521074c | 111 | } |
| Abe_t | 1:a9850521074c | 112 | else if(button[0].read() == 1){ |
| Abe_t | 1:a9850521074c | 113 | LED[0].write(1); |
| Abe_t | 1:a9850521074c | 114 | } |
| Abe_t | 1:a9850521074c | 115 | else if(button[1].read() == 1){ |
| Abe_t | 1:a9850521074c | 116 | LED[1].write(1); |
| Abe_t | 1:a9850521074c | 117 | } |
| Abe_t | 1:a9850521074c | 118 | |
| Abe_t | 1:a9850521074c | 119 | else{ |
| Abe_t | 1:a9850521074c | 120 | counter = 0; |
| Abe_t | 1:a9850521074c | 121 | LED[1].write(0); |
| Abe_t | 1:a9850521074c | 122 | LED[2].write(0); |
| Abe_t | 1:a9850521074c | 123 | LED[0].write(0); |
| Abe_t | 1:a9850521074c | 124 | buzzer.write(0); |
| Abe_t | 8:f0f551fa29d4 | 125 | servo1.rot(265.0); |
| Abe_t | 1:a9850521074c | 126 | motor1.drive(0.0); |
| Abe_t | 1:a9850521074c | 127 | motor2.drive(0.0); |
| Abe_t | 1:a9850521074c | 128 | motor3.drive(0.0); |
| Abe_t | 1:a9850521074c | 129 | } |
| Abe_t | 1:a9850521074c | 130 | |
| Abe_t | 1:a9850521074c | 131 | pc.printf("%f\t %f\t %f\t %d\t \r\n",enco1.getDeg(),enco2.getDeg(),enco3.getDeg(),buzzer.read()); |
| Abe_t | 1:a9850521074c | 132 | system_cycle.reset(); |
| Abe_t | 1:a9850521074c | 133 | }//(while system_cycle ) |
| Abe_t | 1:a9850521074c | 134 | if( ps3.getbutton(cross)==1){break;} |
| Abe_t | 1:a9850521074c | 135 | }//(while) |
| Abe_t | 1:a9850521074c | 136 | } |
| Abe_t | 1:a9850521074c | 137 |
