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
Diff: main.cpp
- Revision:
- 11:39bd79605827
- Parent:
- 10:b7a44c4a4ef6
diff -r b7a44c4a4ef6 -r 39bd79605827 main.cpp
--- a/main.cpp Wed May 29 18:57:39 2019 +0000
+++ b/main.cpp Tue Jun 04 19:03:39 2019 +0000
@@ -78,10 +78,10 @@
pc.printf("Siamo accesi\n\r");
wait(1);
- linkspedal.sendBuffer(495,0);
- rechtspedal.sendBuffer(495,0);
- vorderrad.sendBuffer(495,0);
- hinterrad.sendBuffer(495,0);
+ linkspedal.setTorque(0);
+ rechtspedal.setTorque(0);
+ vorderrad.setTorque(0);
+ hinterrad.setTorque(0);
wait(0.2);
// Pedelec Values
@@ -117,7 +117,7 @@
// PID instance
float Kp = 1.2, Ki = 40, Kd = 0.0;
- PID pid(Kp, Ki, Kd, dt);
+ PID pid(Kp, Ki, Kd, dt, true);
pid.setInputLimits(0.0,200.0);
pid.setOutputLimits(1.0,100.0);
pid.setMode(1); //Regulator
@@ -134,13 +134,13 @@
while(!encoder.reset()){
if(!init){
- rechtspedal.sendBuffer(495,0.8*4096);
+ rechtspedal.setTorque(80);
init = true;
wait(0.04);
- rechtspedal.sendBuffer(495,0.03*4096);
+ rechtspedal.setTorque(3);
}
}
- rechtspedal.sendBuffer(495,0);
+ rechtspedal.setTorque(0);
wait(0.1);
init = false;
float leistungsfaktor = 4.8; // Faktor zwischen Elektrischeleistung und mechanische Leistung %
@@ -216,12 +216,12 @@
// Hilfemoment für Rücktritt steuern
if(F_RPM < -5.0f && !richtung1){
- rechtspedal.sendBuffer(495,0.03*4096);
+ rechtspedal.setTorque(3);
richtung1 = true;
richtung2 = false;
}
else if(F_RPM > -3.0f && !richtung2){
- rechtspedal.sendBuffer(495,0);
+ rechtspedal.setTorque(0);
richtung1 = false;
richtung2 = true;
}
@@ -234,14 +234,14 @@
if(F_RPM > 1.0f && !Bremsen && !recup){
torque = (F_PMech / 300.0 * 100)*pedFaktor;
if(i%10 == 0 && (torque < (torqueOld*0.95) || torque > (torqueOld * 1.05))) {
- vorderrad.sendBuffer(497,0);
- hinterrad.sendBuffer(497,0);
+ vorderrad.setRecuperation(0);
+ hinterrad.setRecuperation(0);
// write torque to phaserunner;
- //vorderrad.sendBuffer(477,uint16_t((80+(torque))*40.96f));
- vorderrad.sendBuffer(495,uint16_t((0.10+(torque/100.0f))*4096));
- //hinterrad.sendBuffer(495,uint16_t((0.20+(torque/100.0f))*4096));
- //vorderrad.sendBuffer(495,0);
- hinterrad.sendBuffer(495,0);
+ //vorderrad.setRecuperation(uint16_t((80+(torque))*40.96f));
+ vorderrad.setTorque(uint16_t(10+torque));
+ //hinterrad.setTorque(uint16_t(20+torque));
+ //vorderrad.setTorque(0);
+ hinterrad.setTorque(0);
write = 10;
torqueOld = torque;
printf("State: torque\n\r");
@@ -256,18 +256,18 @@
writeNull = true;
write = -10;
// write 0 to phaserunner
- vorderrad.sendBuffer(495,0);
- hinterrad.sendBuffer(495,0);
+ vorderrad.setTorque(0);
+ hinterrad.setTorque(0);
}
else write = 0;
if((daumen.getValue() > Phaserunner::MIN_RECUPERATION)&& !recup){
- vorderrad.sendBuffer(495,0);
- hinterrad.sendBuffer(495,0);
+ vorderrad.setTorque(0);
+ hinterrad.setTorque(0);
wait_ms(5);
- vorderrad.sendBuffer(497,uint16_t((float)daumen.getValue()/100.0f*4096));
- hinterrad.sendBuffer(497,uint16_t((float)daumen.getValue()/100.0f*4096));
+ vorderrad.setRecuperation(daumen);
+ hinterrad.setRecuperation(daumen);
printf("State: recup\n\r");
recup = true;
}
@@ -277,11 +277,11 @@
if(Bremsen && !gebremst){
write = -5;
// write 0 to phaserunner
- vorderrad.sendBuffer(495,0);
- hinterrad.sendBuffer(495,0);
+ vorderrad.setTorque(0);
+ hinterrad.setTorque(0);
wait_ms(5);
- vorderrad.sendBuffer(497,uint16_t(0.10f*4096));
- hinterrad.sendBuffer(497,uint16_t(0.10f*4096));
+ vorderrad.setRecuperation(10);
+ hinterrad.setRecuperation(10);
printf("State: bremsen\n\r");
gebremst = true;
}
@@ -296,7 +296,7 @@
float u;
if(i%200 == 0){
i = 0;
- vorderrad.readBuffer(262);
+ //vorderrad.readBuffer(262);
u = vorderrad.getVoltage();
printf("P=%.3f, Torque=%.3f , RPM_Ped =%.3f, U=%.2f\n\r",F_PMech,torque,F_RPM,u);
//printf("Daumen1: %d, Daumen2: %.2f\n\r",wert1,wert2);