![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
raspberry pi to stm32f303k8 for serial communication
Drive/Drive.cpp@0:7bc24e8d1591, 2021-05-02 (annotated)
- Committer:
- mukuyo
- Date:
- Sun May 02 15:01:33 2021 +0000
- Revision:
- 0:7bc24e8d1591
update;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mukuyo | 0:7bc24e8d1591 | 1 | #include "Drive.hpp" |
mukuyo | 0:7bc24e8d1591 | 2 | #define LED_PIN PF_0 |
mukuyo | 0:7bc24e8d1591 | 3 | |
mukuyo | 0:7bc24e8d1591 | 4 | Drive::Drive(PinName CAN_TX, PinName CAN_RX): Rasp(USBTX,USBRX), canMBED(CAN_TX, CAN_RX), LED(LED_PIN), servo(PA_8){ |
mukuyo | 0:7bc24e8d1591 | 5 | initCAN(); |
mukuyo | 0:7bc24e8d1591 | 6 | //can_Timer.attach(callback(this,&UDP::can_send), 16ms); |
mukuyo | 0:7bc24e8d1591 | 7 | count = 0; |
mukuyo | 0:7bc24e8d1591 | 8 | } |
mukuyo | 0:7bc24e8d1591 | 9 | |
mukuyo | 0:7bc24e8d1591 | 10 | void Drive::setVelocity(){ |
mukuyo | 0:7bc24e8d1591 | 11 | //LED=0; |
mukuyo | 0:7bc24e8d1591 | 12 | for(int i = 0; i < 4; i++) |
mukuyo | 0:7bc24e8d1591 | 13 | { |
mukuyo | 0:7bc24e8d1591 | 14 | M[i] = 0; |
mukuyo | 0:7bc24e8d1591 | 15 | Rasp::get(M[i], i); |
mukuyo | 0:7bc24e8d1591 | 16 | } |
mukuyo | 0:7bc24e8d1591 | 17 | dribble_set(); |
mukuyo | 0:7bc24e8d1591 | 18 | calcWheelVelocity(); |
mukuyo | 0:7bc24e8d1591 | 19 | setMotVel(); |
mukuyo | 0:7bc24e8d1591 | 20 | can_send(); |
mukuyo | 0:7bc24e8d1591 | 21 | } |
mukuyo | 0:7bc24e8d1591 | 22 | |
mukuyo | 0:7bc24e8d1591 | 23 | void Drive::dribble_set(){ |
mukuyo | 0:7bc24e8d1591 | 24 | if(dribble_power > 0){ |
mukuyo | 0:7bc24e8d1591 | 25 | dribble_power = 0.25; |
mukuyo | 0:7bc24e8d1591 | 26 | } |
mukuyo | 0:7bc24e8d1591 | 27 | servo = dribble_power; |
mukuyo | 0:7bc24e8d1591 | 28 | } |
mukuyo | 0:7bc24e8d1591 | 29 | |
mukuyo | 0:7bc24e8d1591 | 30 | void Drive::calcWheelVelocity(){ |
mukuyo | 0:7bc24e8d1591 | 31 | |
mukuyo | 0:7bc24e8d1591 | 32 | float max; |
mukuyo | 0:7bc24e8d1591 | 33 | double plus; |
mukuyo | 0:7bc24e8d1591 | 34 | |
mukuyo | 0:7bc24e8d1591 | 35 | order.Mot0Order.Vel_short = M[0]; |
mukuyo | 0:7bc24e8d1591 | 36 | order.Mot1Order.Vel_short = M[1]; |
mukuyo | 0:7bc24e8d1591 | 37 | order.Mot2Order.Vel_short = M[2]; |
mukuyo | 0:7bc24e8d1591 | 38 | order.Mot3Order.Vel_short = M[3]; |
mukuyo | 0:7bc24e8d1591 | 39 | /*order.Mot0Order.Vel_short = -100; |
mukuyo | 0:7bc24e8d1591 | 40 | order.Mot1Order.Vel_short = -100; |
mukuyo | 0:7bc24e8d1591 | 41 | order.Mot2Order.Vel_short = 100; |
mukuyo | 0:7bc24e8d1591 | 42 | order.Mot3Order.Vel_short = 100;*/ |
mukuyo | 0:7bc24e8d1591 | 43 | } |
mukuyo | 0:7bc24e8d1591 | 44 | |
mukuyo | 0:7bc24e8d1591 | 45 | void Drive::setMotVel(){ |
mukuyo | 0:7bc24e8d1591 | 46 | send_motvel_data[0] = (char)order.Mot0Order.Vel_char.L; |
mukuyo | 0:7bc24e8d1591 | 47 | send_motvel_data[1] = (char)order.Mot0Order.Vel_char.H; |
mukuyo | 0:7bc24e8d1591 | 48 | send_motvel_data[2] = (char)order.Mot1Order.Vel_char.L; |
mukuyo | 0:7bc24e8d1591 | 49 | send_motvel_data[3] = (char)order.Mot1Order.Vel_char.H; |
mukuyo | 0:7bc24e8d1591 | 50 | send_motvel_data[4] = (char)order.Mot2Order.Vel_char.L; |
mukuyo | 0:7bc24e8d1591 | 51 | send_motvel_data[5] = (char)order.Mot2Order.Vel_char.H; |
mukuyo | 0:7bc24e8d1591 | 52 | send_motvel_data[6] = (char)order.Mot3Order.Vel_char.L; |
mukuyo | 0:7bc24e8d1591 | 53 | send_motvel_data[7] = (char)order.Mot3Order.Vel_char.H; |
mukuyo | 0:7bc24e8d1591 | 54 | } |
mukuyo | 0:7bc24e8d1591 | 55 | |
mukuyo | 0:7bc24e8d1591 | 56 | void Drive::initCAN(){ |
mukuyo | 0:7bc24e8d1591 | 57 | canMBED.frequency(100000); |
mukuyo | 0:7bc24e8d1591 | 58 | |
mukuyo | 0:7bc24e8d1591 | 59 | } |
mukuyo | 0:7bc24e8d1591 | 60 | |
mukuyo | 0:7bc24e8d1591 | 61 | void Drive::can_send(){ |
mukuyo | 0:7bc24e8d1591 | 62 | canMBED.write(CANMessage(0x1AA,send_motvel_data,8)); |
mukuyo | 0:7bc24e8d1591 | 63 | } |
mukuyo | 0:7bc24e8d1591 | 64 | |
mukuyo | 0:7bc24e8d1591 | 65 | int Drive::masuo_send(){ |
mukuyo | 0:7bc24e8d1591 | 66 | return 1; |
mukuyo | 0:7bc24e8d1591 | 67 | } |