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

Awsome Work, A Couple Simple Questions. #3

Open
bdring opened this issue Jan 14, 2020 · 28 comments
Open

Awsome Work, A Couple Simple Questions. #3

bdring opened this issue Jan 14, 2020 · 28 comments

Comments

@bdring
Copy link

bdring commented Jan 14, 2020

Hey Ben,

Thanks for this awesome open source project. I do a lot of open source work too.

https://github.com/bdring/Grbl_Esp32
https://www.youtube.com/watch?v=M1gXuKFspgY

I stumbled upon one of your designs on AliExpress. I bought one to test. The motor I received looks like this.

20200110_093218

The documentation I received is pretty limited.

I hope to use the motor some sort of fabrication or kinetic art machine. The motor is so clean looking and the wiring can almost be invisible. I am quite excited.

I have been able to move the motor via the CAN bus, but I don’t have a real feel for what values to provide for Kp, Kd and Feed-Forward Current. Is there any guidance you can give me?

Thanks

Bart Dring

@xc-racer99
Copy link

I have been able to move the motor via the CAN bus

Hope you don't mind me butting in, but I've finally someone else with a motor that looks like the one I'm trying to get going :)

I can't seem to make mine move at all - whenever I plug in the 24V only a red led turns on and the CAN bus message I send never receives an ack from the motor. Is the red led normal on the new revisions? Based on videos of the older ones, it should be a green led and the red one indicates a fault. I can backdrive it with my fingers even when the 24V is applied. I'm assuming you've only attached the 24V and the H/L of the CAN bus?

Trying to determine if the problem is my CAN programming/setup or if it's the motor itself.

Thanks!

@bdring
Copy link
Author

bdring commented Jan 14, 2020

It is red at power on. If you send the motor enable signal, it turns green. You can then send it a move command.

Without fully understanding all the parameters, the motor can be very jerky and not get to position. We were able to SWAG some numbers to get it better, (slow and low torque).

I am dumping everything I know in a drive folder. Feel free to browse around. I am not ready to publish my SWAG values until I get a better understanding.

I am not sure if the encoder is calibrated. I did not get a 3 pin UART connector. I ordered a few from Digikey.

@xc-racer99
Copy link

It is red at power on. If you send the motor enable signal, it turns green. You can then send it a move command.

Awesome, thanks for the quick reply. I'll see if I can figure it out :)

@bdring
Copy link
Author

bdring commented Jan 14, 2020

I won't be doing much on it until later this week. If you figure anything out, post it here and I'll add it to the doc/folder

@bengkatz
Copy link

Documentation for my motor drives is here:

https://docs.google.com/document/d/1dzNVzblz6mqB3eZVEMyi2MtSngALHdgpTaDJIW_BpS4/edit?usp=sharing

It has an explanation for what the different commands mean and how to set them in real physical units, but here's a qualitative description of what these terms do.

Kp is desired position stiffness. If you set all commands to zero except for Kp, the motor will behave like a spring with stiffness Kp about the 0 angle.

Kd is velocity gain. Kd acts like a damper. If you set all the commands to zero except Kd and try to spin the motor by hand, you will feel some drag, proportional to Kd.

The feed-forward torque is a bias torque. If you set all the commands to zero except for the feed forward torque, the motor will just apply the torque you set.

All the commands get summed up in the motor drive, so the final torque is:
Kpposition_error + Kdvelocity_error + feedforward_torque

All this being said, the Aliexpress company just copied my schematic, but I have no idea if they made any changes to the firmware,.

@bdring
Copy link
Author

bdring commented Jan 15, 2020

Thanks, that is exactly the guidance I was looking for.

Bart

@bdring
Copy link
Author

bdring commented Jan 18, 2020

@bengkatz

I was able to get everything working. Your explanations really helped. The only thing I don't understand is the velocity value. I don't seem to see any change if behavior when I change the value.

Can you give me a quick description? Maybe show me two examples and what to expect to see differently between them.

Thanks again

Bart

@bgkatz
Copy link
Owner

bgkatz commented Jan 18, 2020

Which velocity value? The desired velocity command, or the velocity gain Kd?

@bdring
Copy link
Author

bdring commented Jan 18, 2020

The desired velocity

@bgkatz
Copy link
Owner

bgkatz commented Jan 18, 2020

You have to set both a desired velocity and a non-zero velocity gain The velocity gain will set how "hard" it tries to track the desired velocity

@bdring
Copy link
Author

bdring commented Jan 18, 2020

Thanks, I am starting to get a feel for it.

To go at a specific velocity, the kd value needs to be higher than the kp value.

@bgkatz
Copy link
Owner

bgkatz commented Jan 18, 2020

If you are just trying to control velocity, you should set Kp to zero or it will fight against your velocity command.

@bdring
Copy link
Author

bdring commented Jan 22, 2020

Starting to make some progress. Thanks for all the help.

See the video on this tweet.

https://twitter.com/buildlog/status/1219807520816017409

@bdring
Copy link
Author

bdring commented Feb 27, 2020

@bgkatz I am still playing with this motor as I get time. I have loaded your firmware and the motor appears to work the same as before, so I doubt they changed your firmware much.

I did tweak the gear ratio because my motor has a 6:1 reduction. The range of motion seems to match the +/-12.5 radians of the firmware.

When I send it a command, the motor will move with the values I give it, but it never appears to reach its target position. with low values for kp, kd and ff it can be as far as a radian away. If I send the same position values, but higher kp, kd, and ff values it moves closer. If I max out Kp it gets pretty close, but is very stiff.

I would like to be able to tune it so it always reaches the target, but has adjustable stiffness.

I hope make some sort of CNC machine, like a delta or SCARA. I am thinking about adding a CAN command that disables the UART on the fly and converts those pins to step and direction inputs.

@nyxrobotics
Copy link

I bought same motor from Steadywin(on aliexpress).
I want to upgrade the firmware with mbed compiler. Which target board shall I select?

@bdring
Copy link
Author

bdring commented Feb 27, 2020

@nyxrobotics I documented what I did to program it

I hope it helps.

@nyxrobotics
Copy link

@bdring Thank you so much! I will try it tomorrow.

@nyxrobotics
Copy link

I was able to write the firmware, thank you!

The motor moves pretty well in normal operation, but I sometimes get "1f" message on serial terminal, and the motor won't move untill reboot.
Don't you have this problem?

@bdring
Copy link
Author

bdring commented Mar 2, 2020

The "1f" is normal operation. It is on line 63.

printf("%df\n\r", rxMsg.id);

It is printing the message id of the received CAN message on all messages. I am not sure why it is printing the f. It initially fooled me into thinking it was a hex value. It never has any effect on my operation.

@nyxrobotics
Copy link

Thak you for your reply!
The "1f" message was just CAN target ID...
We are investigating the problem of resetting the MCU while the motor is rotating, and the motor will not work unless the encoder is recalibrated.....

@nyxrobotics
Copy link

I replaced the power supply with one with a higher allowable current. It came to move stably.
However, I can't set any CAN command for ID "4".
While I send the packet for ID 4, CAN::_irq_handler is not called.
It seems that mbed-dev issue.
Does anyone have same problem ?

@nyxrobotics
Copy link

I found that ID numbers of "0bxxxxx1xx" pattern, such as 4,5,6,7,12,13,14,15 don't work.

@nyxrobotics
Copy link

I comented out line 537 and it works pretty well. Thank you!

    //can.filter(CAN_ID<<21, 0xFFE00004, CANStandard, 0);

@bgkatz
Copy link
Owner

bgkatz commented Mar 18, 2020

Sounds like you are on an old version of the firmware, which likely has other bugs as well. The link to the latest fork is in the documentation Google doc or here
https://os.mbed.com/users/benkatz/code/HKC_MiniCheetah/

Commenting out that line will cause every motor drive to go into the CAN interrupt any time any message is sent on the CAN bus, which is not at all what you want.

@NekoSaiKou
Copy link

Documentation for my motor drives is here:

https://docs.google.com/document/d/1dzNVzblz6mqB3eZVEMyi2MtSngALHdgpTaDJIW_BpS4/edit?usp=sharing

It has an explanation for what the different commands mean and how to set them in real physical units, but here's a qualitative description of what these terms do.

Kp is desired position stiffness. If you set all commands to zero except for Kp, the motor will behave like a spring with stiffness Kp about the 0 angle.

Kd is velocity gain. Kd acts like a damper. If you set all the commands to zero except Kd and try to spin the motor by hand, you will feel some drag, proportional to Kd.

The feed-forward torque is a bias torque. If you set all the commands to zero except for the feed forward torque, the motor will just apply the torque you set.

All the commands get summed up in the motor drive, so the final torque is:
Kp_position_error + Kd_velocity_error + feedforward_torque

All this being said, the Aliexpress company just copied my schematic, but I have no idea if they made any changes to the firmware,.

Dear all,

The explanations really helped. I got pure velocity control and pure position control work too.
However, I wonder why a PD controller is selected instead of the classical multi-loop(position, velocity, or torque) controller for servo motor. With only PD control, I found it difficult to control the position and velocity at the same time. Can anyone explain that to me.

Thanks

@bgkatz
Copy link
Owner

bgkatz commented Sep 4, 2020

Dear all,

The explanations really helped. I got pure velocity control and pure position control work too.
However, I wonder why a PD controller is selected instead of the classical multi-loop(position, velocity, or torque) controller for servo motor. With only PD control, I found it difficult to control the position and velocity at the same time. Can anyone explain that to me.

Thanks

It's not quite a classic PD controller, which would only take a position command, and would take the derivative of the position error to get the derivative term. The position + velocity commands with position + velocity proportional gains is equivalent to the classic PD controller in continuous time, IF the position and velocity commands are consistent with each other, but is works better when commands are sent slower than the control loop is updated.

Which brings up the point - you fundamentally can't do independent position and velocity control. If you want to control to a trajectory, you should send position and velocity commands that are consistent with each other, i.e. the velocity command integrates to the position command.

To summarize how it was intended to be used:

  • If you want to just control velocity set the position gain to zero. If you want better steady-state error rejection, you can wrap an integrator around it yourself using the feedforward torque term.
  • if you want to just control position, and you do not care about the trajectory the motor takes between position setpoints, set BOTH Kp and Kd to be non-zero (if Kd is zero it will oscillate), send 0 velocity command, and send whatever position command you want. This will behave "sluggishly", because the derivative term acts like damping on the rotation, always trying to slow the speed down to zero, but it will work.
  • if you want best performance and to track a trajectory, set both Kp and Kd to be non-zero, and send continuously changing position and velocity setpoints along your trajectory, which are consistent with eachother.

The motor drive itself will not generate intelligent trajectories (e.g. trapezoidal velocity profiles between position setpoints), that is up to you to do on whatever is controlling the motor. But if you can generate the trajectories, you should be able to send self-consistent position and velocity commands to track it.

Hopefully that clears up any confusion

@NekoSaiKou
Copy link

That is pretty interesting. I will do more research on command generation and motion planning.
Thanks for your detailed explanation.

@Gius-8
Copy link

Gius-8 commented Dec 10, 2020

Nowadays, is anyone able to compile the firmware? I can't import it into the mbed cloud compiler. I can't even compile it with mbed CLI and mbed Studio. I believe the cause is due to the version of the mbed library.
Can someone please help me?

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

7 participants