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.
Dependencies: mbed PID mbed-rtos
main.cpp@0:8a660654d511, 2019-04-20 (annotated)
- Committer:
- EpicG10
- Date:
- Sat Apr 20 10:01:22 2019 +0000
- Revision:
- 0:8a660654d511
- Child:
- 1:71457a2df34a
Da Testare
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| EpicG10 | 0:8a660654d511 | 1 | #include "mbed.h" |
| EpicG10 | 0:8a660654d511 | 2 | #include "Encoder.h" |
| EpicG10 | 0:8a660654d511 | 3 | #include "math.h" |
| EpicG10 | 0:8a660654d511 | 4 | #include "Phaserunner.h" |
| EpicG10 | 0:8a660654d511 | 5 | |
| EpicG10 | 0:8a660654d511 | 6 | Encoder encoder; |
| EpicG10 | 0:8a660654d511 | 7 | RawSerial pedalL(PC_10, PC_11, 115200); |
| EpicG10 | 0:8a660654d511 | 8 | RawSerial pedalR(PC_12, PD_2, 115200); |
| EpicG10 | 0:8a660654d511 | 9 | Phaserunner linkspedal(pedalL); |
| EpicG10 | 0:8a660654d511 | 10 | Phaserunner rechtspedal(pedalR); |
| EpicG10 | 0:8a660654d511 | 11 | |
| EpicG10 | 0:8a660654d511 | 12 | int main(){ |
| EpicG10 | 0:8a660654d511 | 13 | DigitalOut PedalL_ON_OFF(PC_14); |
| EpicG10 | 0:8a660654d511 | 14 | DigitalOut PedalR_ON_OFF(PC_15); |
| EpicG10 | 0:8a660654d511 | 15 | |
| EpicG10 | 0:8a660654d511 | 16 | |
| EpicG10 | 0:8a660654d511 | 17 | InterruptIn NullStell(PA_13); |
| EpicG10 | 0:8a660654d511 | 18 | Serial pc(USBTX,USBRX); |
| EpicG10 | 0:8a660654d511 | 19 | DigitalOut led(LED2); |
| EpicG10 | 0:8a660654d511 | 20 | DigitalOut ON_OFF(PH_1); |
| EpicG10 | 0:8a660654d511 | 21 | |
| EpicG10 | 0:8a660654d511 | 22 | DigitalOut Abvorne(PB_7); |
| EpicG10 | 0:8a660654d511 | 23 | DigitalOut Abhinten(PC_13); |
| EpicG10 | 0:8a660654d511 | 24 | |
| EpicG10 | 0:8a660654d511 | 25 | ON_OFF = true; |
| EpicG10 | 0:8a660654d511 | 26 | |
| EpicG10 | 0:8a660654d511 | 27 | uint32_t pulses=0, pulsesOld=0; |
| EpicG10 | 0:8a660654d511 | 28 | double angle_rad, angle_grad, angleOld=0; |
| EpicG10 | 0:8a660654d511 | 29 | float a=0.0f,b=0.0f,beta=0.0f; // Ellipse Parameters |
| EpicG10 | 0:8a660654d511 | 30 | float R=0.0f, phi=0.0f; |
| EpicG10 | 0:8a660654d511 | 31 | |
| EpicG10 | 0:8a660654d511 | 32 | PedalL_ON_OFF = true; |
| EpicG10 | 0:8a660654d511 | 33 | PedalR_ON_OFF = true; |
| EpicG10 | 0:8a660654d511 | 34 | wait(0.2); |
| EpicG10 | 0:8a660654d511 | 35 | PedalL_ON_OFF = false; |
| EpicG10 | 0:8a660654d511 | 36 | PedalR_ON_OFF = false; |
| EpicG10 | 0:8a660654d511 | 37 | wait(0.2); |
| EpicG10 | 0:8a660654d511 | 38 | PedalL_ON_OFF = true; |
| EpicG10 | 0:8a660654d511 | 39 | PedalR_ON_OFF = true; |
| EpicG10 | 0:8a660654d511 | 40 | |
| EpicG10 | 0:8a660654d511 | 41 | |
| EpicG10 | 0:8a660654d511 | 42 | led = false; |
| EpicG10 | 0:8a660654d511 | 43 | pc.printf("Hello bike"); |
| EpicG10 | 0:8a660654d511 | 44 | //NullStell.rise(&GetNull); |
| EpicG10 | 0:8a660654d511 | 45 | while(1){ |
| EpicG10 | 0:8a660654d511 | 46 | |
| EpicG10 | 0:8a660654d511 | 47 | //rev = Encoder.getRevolutions(); |
| EpicG10 | 0:8a660654d511 | 48 | pulses = encoder.read(); |
| EpicG10 | 0:8a660654d511 | 49 | angle_rad = encoder.readAngle(); |
| EpicG10 | 0:8a660654d511 | 50 | |
| EpicG10 | 0:8a660654d511 | 51 | if(pulses != pulsesOld){ |
| EpicG10 | 0:8a660654d511 | 52 | pc.printf("pulses: %d\n\r",pulses); |
| EpicG10 | 0:8a660654d511 | 53 | } |
| EpicG10 | 0:8a660654d511 | 54 | if(angle_rad != angleOld){ |
| EpicG10 | 0:8a660654d511 | 55 | pc.printf("Angle: %.3f\n\r",angle_rad); |
| EpicG10 | 0:8a660654d511 | 56 | } |
| EpicG10 | 0:8a660654d511 | 57 | phi = angle_rad; |
| EpicG10 | 0:8a660654d511 | 58 | // Calcolation of R |
| EpicG10 | 0:8a660654d511 | 59 | float P_Factor = 0.5f; |
| EpicG10 | 0:8a660654d511 | 60 | a = 1.0f; |
| EpicG10 | 0:8a660654d511 | 61 | b = 0.5f; |
| EpicG10 | 0:8a660654d511 | 62 | beta = 0.0f; |
| EpicG10 | 0:8a660654d511 | 63 | R=sqrt(pow(a,2) * pow(sin(beta + phi),2) + pow(b,2) * pow(cos(beta + phi),2)); |
| EpicG10 | 0:8a660654d511 | 64 | |
| EpicG10 | 0:8a660654d511 | 65 | linkspedal.setTorque(R*P_Factor); |
| EpicG10 | 0:8a660654d511 | 66 | rechtspedal.setTorque(R*P_Factor); |
| EpicG10 | 0:8a660654d511 | 67 | pc.printf("Torque: %f\n\r",R*P_Factor); |
| EpicG10 | 0:8a660654d511 | 68 | angleOld = angle_rad; |
| EpicG10 | 0:8a660654d511 | 69 | pulsesOld = pulses; |
| EpicG10 | 0:8a660654d511 | 70 | |
| EpicG10 | 0:8a660654d511 | 71 | wait_ms(100); |
| EpicG10 | 0:8a660654d511 | 72 | |
| EpicG10 | 0:8a660654d511 | 73 | } |
| EpicG10 | 0:8a660654d511 | 74 | |
| EpicG10 | 0:8a660654d511 | 75 | |
| EpicG10 | 0:8a660654d511 | 76 | |
| EpicG10 | 0:8a660654d511 | 77 | } |