7 Commits

Author SHA1 Message Date
6fff0e1055 pwm 2025-08-06 04:18:59 -04:00
dd7ad1b54e pwm 2025-08-06 04:17:28 -04:00
698fe61657 pwm 2025-08-06 04:14:48 -04:00
095e34ce77 pwm 2025-08-06 04:12:14 -04:00
07dee7bca4 pwm 2025-08-06 04:09:27 -04:00
a7bdd21c34 pwm 2025-08-06 03:44:10 -04:00
2133918eeb pwm 2025-08-06 03:27:22 -04:00
3 changed files with 34 additions and 3 deletions

View File

@@ -379,8 +379,8 @@ void onDataReceived (const uint8_t *mac_addr, const uint8_t *data, uint8_t data_
rc_x = buf.x_axis; // Save joystic x-axis value
rc_y = buf.y_axis; // Save joystic y-axis value
update_pwm(rc_x, rc_y);
mqtt_update_pwm_1(rc_x);
mqtt_update_pwm_2(rc_y);
mqtt_update_pwm_1(rc_x); // Publish PWM-1 on MQTT Broker
mqtt_update_pwm_2(rc_y); // Publish PWM-2 on MQTT Broker
}
void ultrasonic_task (void *arg) {

View File

@@ -1,5 +1,5 @@
#ifndef MOTOR_CONTROLS_H
#define MOTOR_CONTROLSC_H
#define MOTOR_CONTROLS_H
// Interpolate value (x) based on raw reading, min/max limits.
/*

View File

@@ -98,6 +98,37 @@ static void update_pwm (int rc_x, int rc_y) {
if (1024 < x < 2048 && 1024 < y < 2048) {
}*/
// Smooth update
// All forward directions
if (y >= 1500) {
m.motor1_rpm_pcm = (y - x); // Left side motors, forward
m.motor2_rpm_pcm = (y + x); // Right side motors, forward
m.motor3_rpm_pcm = 0;
m.motor4_rpm_pcm = 0;
}
// All reverse directions
if (y <= -1500) {
m.motor1_rpm_pcm = 0;
m.motor2_rpm_pcm = 0;
m.motor3_rpm_pcm = -(y - x); // Left side motors, reverse
m.motor4_rpm_pcm = -(y + x); // Right side motors, reverse
}
// ROTATIONS
// Rotate right
if ((y < 1500) && (y > 1500)) && (x > 8000) {
m.motor1_rpm_pcm = (y - x);
m.motor2_rpm_pcm = 0;
m.motor3_rpm_pcm = -(y - x);
m.motor4_rpm_pcm = 0;
}
if ((y < 1500) && (y > 1500)) && (x < 8000) {
m.motor1_rpm_pcm = 0;
m.motor2_rpm_pcm = (y + x);
m.motor3_rpm_pcm = -(y - x);
m.motor4_rpm_pcm = 0;
}
// -------------
// Turn Left
if (x == 8190 && y == -8190) {
m.motor1_rpm_pcm = 6172;