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
Diff: main.cpp
- Revision:
- 2:8619b626ef7d
- Parent:
- 1:0b6d558a5431
- Child:
- 3:aef2dcb63762
--- a/main.cpp Tue Nov 23 12:54:08 2021 +0000
+++ b/main.cpp Fri Dec 10 04:03:14 2021 +0000
@@ -5,12 +5,13 @@
#define PI 3.14159265358979f
-#define MOTOR1_FORWARD PC_1
-#define MOTOR1_REVERSE PC_0
+#define MOTOR2_FORWARD PA_13
+#define MOTOR2_REVERSE PA_14
+#define MOTOR2_PWM PA_15
+
+#define MOTOR1_FORWARD PC_0
+#define MOTOR1_REVERSE PC_1
#define MOTOR1_PWM PB_0
-#define MOTOR2_FORWARD PC_15
-#define MOTOR2_REVERSE PC_14
-#define MOTOR2_PWM PB_1
#define PULSE_ENCODER 84
@@ -39,8 +40,8 @@
Motor motor1 (MOTOR1_PWM, MOTOR1_FORWARD, MOTOR1_REVERSE);
Motor motor2 (MOTOR2_PWM, MOTOR2_FORWARD, MOTOR2_REVERSE);
-encoderKRAI encoder1 (ENCODER1_CHANNEL_A, ENCODER1_CHANNEL_B, PULSE_ENCODER, encoderKRAI::X4_ENCODING);
-encoderKRAI encoder2 (ENCODER2_CHANNEL_A, ENCODER2_CHANNEL_B, PULSE_ENCODER, encoderKRAI::X4_ENCODING);
+encoderKRAI encoder2 (ENCODER1_CHANNEL_A, ENCODER1_CHANNEL_B, PULSE_ENCODER, encoderKRAI::X4_ENCODING);
+encoderKRAI encoder1 (ENCODER2_CHANNEL_A, ENCODER2_CHANNEL_B, PULSE_ENCODER, encoderKRAI::X4_ENCODING);
pidLo pid_motor1(a_kp, a_ki, 0, a_TS, 1, 0, 1000, 100);
pidLo pid_motor2(b_kp, b_ki, 0, b_TS, 1, 0, 1000, 100);
@@ -57,8 +58,12 @@
uint32_t sampling_time = 0;
uint32_t sampling_debug = 0;
+float pengali = 1.0;
+
int main() {
while(1) {
+ 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();
@@ -76,14 +81,14 @@
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 >= MOTOR_SAMP_US){
- // motor.speeda_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);
+//// b_pwm = pid_motor1.createpwm(v1_target, v1_curr, 1.0);
+// }
}
}