Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arduino code #4

Open
Ktysai opened this issue Oct 24, 2020 · 9 comments
Open

arduino code #4

Ktysai opened this issue Oct 24, 2020 · 9 comments

Comments

@Ktysai
Copy link

Ktysai commented Oct 24, 2020

Hello!

A wonderful job! Can you help me a little bit with the speed_to_pwm ration. How did you obtain it?

All the best!

@bekirbostanci
Copy link

bekirbostanci commented Oct 24, 2020

Hi @Ktysai
const double speed_to_pwm_ratio = 0.00235; //Ratio to convert speed (in m/s) to PWM value. It was obtained by plotting the wheel speed in relation to the PWM motor command (the value is the slope of the linear function).

In the ros we are use cmd_vel topics for the control diff drive robots. That cmd_vel topics message type is geometry_msgs::Twist and this message include linear_x and angular_z. You can calculate motor speeds for this information. That is the first part.

We are coming your question. What is the speed_to_pwm_ratio constant. This constant convert wheel speed to pwm. Firstly you have to give 255 pwm your motor and detect the your motor max rpm. That is your max motor speed. After this process you have to calculate your circumference of the wheel. 2 * pi * your_wheel_radius. After circumference * (rpm / 60) give meter/sec. This is your speed but still this unit is not pwm.

Result :
For example my max speed 1 m/sec. Computer send the 1 m/sec with cmd_vel I have convert the pwm with this constant. If we know the max_rpm of my motor I can calculate this coefficient.

circumference = 2 * pi * your_wheel_radius
max_speed = circumference * (max_rpm / 60) 
speed_to_pwm_ratio = (max_speed / 255)

I tried to explain in detail as much as I could, if there is another topic I can help with, feel free to ask.

@Ktysai
Copy link
Author

Ktysai commented Oct 24, 2020

@bekirbostanci 👍
Lovely explanation and an over all good project for ROS beginners as my self! The ROS is not that problematic as hardware interface :)

Practically you've given it a test in real life, not the specification given by the manufacturer. I guess the test is with no load, with wheels not touching the surface.

The minimum speed is tested with the robot with all the components mounted?

I was testing the Sungjik version with some modifications of the project, but sometimes with a joystick command
given in ROS, the wheels were rolling a little bit in the opposite direct of the movement and then were ok, with the right speed and direction. The <PID_v1.h> seems to work well here.

In my case I use an Leonardo clone and I'll have to do some tweaking since the dinamic memory is used a lot the by program.

When I've tested the robot I've had a encoder malfunction and the wheel was starting to go wild due to PID. I'll try to do a nocommloop thingy, that I've seen it's implemented here like if no_encoder_ticks AND PWM_command is_not 0, then PWM = 0. Is the proper way?

Thanks for the work and for in for provided!

All the best,
Ktysai

@bekirbostanci
Copy link

It has been a long time since I used this project. As far as I remember, although we used a brushed dc motor, the result was not very efficient although the pid worked correctly. If you think your data from your encoders are incorrect and the encoder counts incorrectly, it is quite natural that the motor will speed up and cannot be controlled. Since the parameter you will enter here will be the same for 2 wheels and it will be balanced with pid, I think you do not need to adjust it very precisely.

@Ktysai
Copy link
Author

Ktysai commented Oct 24, 2020

No, problem!

I want to go into the BLDC, but the ones with encoders aren't that cheap, plus a proper controllers, so for tests I'll still use them.
With BLDC, the torque is really high even at low speeds?

@bekirbostanci
Copy link

Yes normally bldc motors torque control is not very easy task. There are some different methods for example foc field oriented control. You can search if you want to control more properly

@Ktysai
Copy link
Author

Ktysai commented Oct 27, 2020

I know you've said it was a long time ago since the code was developed., but maybe you have a hint.

A big chunk of my code is based on yours, but I've had a lot of trouble in making the motor to obey the maximum speed.

The following line: speed_cmd_left is used to control the, but the motor speed exceeds the maxim speed.

speed_cmd_left = constrain(speed_cmd_left, -max_speed, max_speed);

If the speed_cmd_left is changed with speed_req_left the speed of the motor is properly constrained.

Is there something that i miss in my code?

@bekirbostanci
Copy link

Hi again
This line only limited your cmd_left value.
speed_cmd_left = constrain(speed_cmd_left, -max_speed, max_speed);

Actually I don't know the problem completely know. If your encoder get true value and kp ki kd values are appropriate, bellow line code should convert your speed value to pwm.
PWM_leftMotor = constrain(((speed_req_left+sgn(speed_req_left)*min_speed_cmd)/speed_to_pwm_ratio) + (speed_cmd_left/speed_to_pwm_ratio), -255, 255);

If you are know limited your motor speed somethings goes to wrong. Maybe encoders not count all pulse but it is unlikely.
But you can check your encoder this way. Write a small arduino code and give motor to 255 pwm and encoders also count all pulse. Before the starting code keep a counter ready and start both arduino code and counter at the same time check how many pulses you get after 60 seconds and calculate the expected value and compare your expected value and measured total pulse. If this 2 values are close pid values is not correct I think.

@Ktysai
Copy link
Author

Ktysai commented Oct 31, 2020

@bekirbostanci, thanks again!

If I look at the rostopic "speed", speed_req_left & speed_req_left looks as expected. speed_cmd_left is changing very fast, but the numbers usually are far beyond the required speed, no matter what maximum speed is specified. Maybe is a displaying issue, since the topic is not refreshed that often. I have not used the serial of arduino to debug, yet :((

Encoders seems to be ok, I'll recheck them anyway, since it's easy to have a mismatched constant there. I'm using these motors.

I'll have to recheck the code again, to be sure that there's no improper ratio involved. At the moment with speed_req_left constrained the code works.

The idea of constraining the speed_req_left was born after seeing that speed_cmd_left might be already constrained by this line.

PID_leftMotor.SetOutputLimits(-max_speed, max_speed);

In any case, a lovely code that helps a lot a ROS robot development.

All the best!

@Agri-Mechatronic
Copy link

It has been a long time since I used this project. As far as I remember, although we used a brushed dc motor, the result was not very efficient although the pid worked correctly. If you think your data from your encoders are incorrect and the encoder counts incorrectly, it is quite natural that the motor will speed up and cannot be controlled. Since the parameter you will enter here will be the same for 2 wheels and it will be balanced with pid, I think you do not need to adjust it very precisely.

Hello, can we use differential drive (diff_tf.py) instead of nox_controller.cpp.If yes do you think that will effect in efficiency.Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants