![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
農作物回収機構プログラム
Dependencies: mbed arrc_mbed Motor
main.cpp@0:417f3396cf67, 2022-02-02 (annotated)
- Committer:
- m2130
- Date:
- Wed Feb 02 11:27:13 2022 +0000
- Revision:
- 0:417f3396cf67
- Child:
- 1:7937f28c742d
nousakubutsu kaisyuuuuuuuuuuuuu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m2130 | 0:417f3396cf67 | 1 | //-----Libraries----- |
m2130 | 0:417f3396cf67 | 2 | #include "mbed.h" |
m2130 | 0:417f3396cf67 | 3 | #include "scrp_slave.hpp" |
m2130 | 0:417f3396cf67 | 4 | #include "motor.hpp" |
m2130 | 0:417f3396cf67 | 5 | |
m2130 | 0:417f3396cf67 | 6 | //-----Classes----- |
m2130 | 0:417f3396cf67 | 7 | ScrpSlave slave(PC_12, PD_2, PH_1, SERIAL_TX, SERIAL_RX, 4); //id: 4 |
m2130 | 0:417f3396cf67 | 8 | Motor motor(PB_14, PB_13); |
m2130 | 0:417f3396cf67 | 9 | |
m2130 | 0:417f3396cf67 | 10 | //-----Constants----- |
m2130 | 0:417f3396cf67 | 11 | const double pwm = 0.1; |
m2130 | 0:417f3396cf67 | 12 | |
m2130 | 0:417f3396cf67 | 13 | //-----Sub Routines----- |
m2130 | 0:417f3396cf67 | 14 | bool Up(int RX,int &TX); |
m2130 | 0:417f3396cf67 | 15 | bool Down(int RX,int &TX); |
m2130 | 0:417f3396cf67 | 16 | |
m2130 | 0:417f3396cf67 | 17 | //-----Variables----- |
m2130 | 0:417f3396cf67 | 18 | int up = 0; |
m2130 | 0:417f3396cf67 | 19 | int down = 0; |
m2130 | 0:417f3396cf67 | 20 | |
m2130 | 0:417f3396cf67 | 21 | //-----Main Routine----- |
m2130 | 0:417f3396cf67 | 22 | int main(){ |
m2130 | 0:417f3396cf67 | 23 | slave.addCMD(1, Up); |
m2130 | 0:417f3396cf67 | 24 | slave.addCMD(2, Down); |
m2130 | 0:417f3396cf67 | 25 | while(1){ |
m2130 | 0:417f3396cf67 | 26 | motor.out(pwm * (up + down)); |
m2130 | 0:417f3396cf67 | 27 | } |
m2130 | 0:417f3396cf67 | 28 | } |
m2130 | 0:417f3396cf67 | 29 | |
m2130 | 0:417f3396cf67 | 30 | bool Up(int RX, int &TX){ |
m2130 | 0:417f3396cf67 | 31 | up = RX; |
m2130 | 0:417f3396cf67 | 32 | return true; |
m2130 | 0:417f3396cf67 | 33 | } |
m2130 | 0:417f3396cf67 | 34 | |
m2130 | 0:417f3396cf67 | 35 | bool Down(int RX, int &TX){ |
m2130 | 0:417f3396cf67 | 36 | down = -RX; |
m2130 | 0:417f3396cf67 | 37 | return true; |
m2130 | 0:417f3396cf67 | 38 | } |