KRAI ITB GARUDAGO / Mbed 2 deprecated frictionwheel

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kelvinsutirta
Date:
Fri Dec 17 08:53:50 2021 +0000
Parent:
2:8619b626ef7d
Commit message:
with PID;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Dec 10 04:03:14 2021 +0000
+++ b/main.cpp	Fri Dec 17 08:53:50 2021 +0000
@@ -22,18 +22,18 @@
 
 #define ENC_MOTOR_SAMP_US 20000
 #define MOTOR_SAMP_US 5173
-#define PID_SAMP_US 4173
+#define PID_SAMP_US 20000
 #define S_TO_US       1000000
 
 #define a_kp 0.0
 #define a_ki 0.0
 #define a_kd 0.0
-#define a_TS 0.007
+#define a_TS 0.02
 
 #define b_kp 0.0
 #define b_ki 0.0
 #define b_kd 0.0
-#define b_TS 0.007
+#define b_TS 0.02
 
 #define WHEEL_RAD 0.069        //meter
 
@@ -52,6 +52,8 @@
 int pulse2 = 0;
 float v1_curr = 0;
 float v2_curr = 0;
+float v1_target = 5;
+float v2_target = 5;
 float a_pwm;
 float b_pwm;
 
@@ -62,8 +64,8 @@
 
 int main() {
     while(1) {
-        motor1.speed(pengali*1.00);
-        motor2.speed(pengali*0.980);
+        //motor1.speed(pengali*1.00);
+//        motor2.speed(pengali*0.980);
         if (us_ticker_read()-sampling_time >= ENC_MOTOR_SAMP_US) {
             pulse1 = encoder1.getPulses();
             pulse2 = encoder2.getPulses();
@@ -81,10 +83,10 @@
             sampling_debug = us_ticker_read();
         }
         
-       // if(us_ticker_read()-sampling_debug >= PID_SAMP_US){
-//           // a_pwm = pid_motor1.createpwm(v1_target, v1_curr, 1.0);
-////            b_pwm = pid_motor1.createpwm(v1_target, v1_curr, 1.0);
-//        }
+        if(us_ticker_read()-sampling_debug >= PID_SAMP_US){
+            a_pwm = pid_motor1.createpwm(v1_target, v1_curr, 1.0);
+            b_pwm = pid_motor1.createpwm(v1_target, v1_curr, 1.0);
+            }
 //        
 //        if(us_ticker_read()-sampling_debug >= MOTOR_SAMP_US){
 ////            motor.speeda_pwm = pid_motor1.createpwm(v1_target, v1_curr, 1.0);