UCTRONICS / UCTRONICS_Smart_Robot_Car_RaspberryPi

21 stars 18 forks source link

Controlling the speed of each motor #2

Open tsmalls93 opened 5 years ago

tsmalls93 commented 5 years ago

How does one control the velocity of each motor? I am trying to figure out a way to integrate this with ROS and an RPLIDAR A1 to build a tour robot that uses SLAM navigation. Functions like go_left(void) are not very useful for this. I think it would be nice to be able to specify velocities like:

void set_velocity_front_left(double velocity);
void set_velocity_front_right(double velocity);
void set_velocity_back_left(double velocity);
void set_velocity_back_right(double velocity);

Is this possible or would I need a different motor driver board?

Kilozen commented 5 years ago

Related question: Is it possible to rapidly 'pulse' the motors on and off for slower speeds, or would that damage them?

tsmalls93 commented 5 years ago

Related question: Is it possible to rapidly 'pulse' the motors on and off for slower speeds, or would that damage them?

You can adjust the motor PWM through the phone app, so you can do it through code too. Just don't go over the max. From my research, there is no way to precisely control the angular velocity without encoders. I ordered photo interrupters and encoder disks to measure the angular velocity of the motors, so I can use a PID controller algorithm to adjust the PWM to the desired speed. I will have to redo the drivers though.

kouui commented 4 years ago

@tsmalls93

Have you created the functions for adjusting Linear and Angular speed? I am also going to build a SLAM project using this robot car. I would be gratefule if you could share your code of controlling the robot car.

Thank your for your attention to this matter.

tsmalls93 commented 4 years ago

@kouui sorry for the late response. First off, I do not recommend this car for this purpose. I got it working, but I had to do significant modifications. It essentially was not the same car anymore. I ended up using an Arduino for the motor drivers and I wrote a Python script for ROS to talk to it over USB. In any case, the motors are not adequate enough for AMCL navigation. You will want ones with built-in encoders like the Dynamixel. I also would not recommend the Raspberry Pi or Arduino. I would check out the Turtlebots and base your robot off the parts they use or just buy a Turtlebot.