4WD omni wheel robot, Moving to a direction

Hello, i bought the4WD omni wheel robot, i succeded rotating the robot.
I want to add a function with input the direction (radians or degrees) and the the robot can move to this direction. Can someone help me for coding ?

Rotation function that works :

void rotation () {

  analogWrite(PWM1,200);
  digitalWrite(IN1,HIGH);
  analogWrite(PWM2,200);
  digitalWrite(IN2,HIGH);
  analogWrite(PWM3,200);
  digitalWrite(IN3,HIGH);
  analogWrite(PWM4,200);
  digitalWrite(IN4,HIGH);   

}

1 Like

Hello @Isma ,

Maybe this can be helpful:

#include <math.h>  // Include for trigonometric functions

// ... (Your existing rotate() function and pin definitions)

void steer(float angle, bool isRadians = false) {
  // Convert to radians if input is in degrees
  if (!isRadians) {
    angle = angle * M_PI / 180.0;  
  }

  // Determine individual wheel speeds based on angle
  int frontLeftSpeed = 200 * (cos(angle) - sin(angle));
  int frontRightSpeed = 200 * (cos(angle) + sin(angle));
  int backLeftSpeed = 200 * (-cos(angle) - sin(angle));
  int backRightSpeed = 200 * (-cos(angle) + sin(angle));

  // Apply speeds and directions to motors (adjust for your wiring)
  digitalWrite(IN1, frontLeftSpeed >= 0 ? HIGH : LOW);
  analogWrite(PWM1, abs(frontLeftSpeed));

  digitalWrite(IN2, frontRightSpeed >= 0 ? HIGH : LOW);
  analogWrite(PWM2, abs(frontRightSpeed));

  digitalWrite(IN3, backLeftSpeed >= 0 ? HIGH : LOW);
  analogWrite(PWM3, abs(backLeftSpeed));

  digitalWrite(IN4, backRightSpeed >= 0 ? HIGH : LOW);
  analogWrite(PWM4, abs(backRightSpeed));
}

Thank you, it looks working but when it’s about low speed in some wheels, the robot doesn’t move, looks like it’s too heavy for the motors. Is it normal ?

Angle : 1,5708 (180°)
Speed for each wheel :
image

Didn’t find a solution

1 Like

Maybe you need to synchronize it better.

Something like this:

That’s only predefined direction where the wheels need the same speed. Not a personalised direction.