SolidGeek / VescUart

An Arduino library for interfacing with the VESC over UART
GNU General Public License v3.0
177 stars 92 forks source link

Feature Request- Position Control #30

Open h2omatt opened 3 years ago

h2omatt commented 3 years ago

I'm trying to something a bit different with the VESC. I want to try to use it like a servo drive and be able to do positional control. The motor I'm using has hall sensors and the VESC performs very well at slow speed because of the hall sensor feedback.

My goal is to do position hold but with current limiting. if the torque is higher than the current limit the motor will "slip" and the reset its new position its position hold.

I had previously wrote you asking about speed control using current input. I got this working very well using a PID loop on my Arduino to modulate setCurrent based on UART.data.rpm. This makes me think I can do the same thing for a position hold. User would enter the max current force allowed. then the motor will try to maintain that position unless a greater force is applied causing it to "slip" the reset it will reset is new position as "zero". I will probably have some deadband error range for the position hold so that it only resets home when a major slip even happens.

what's your thoughts? Is there an easier way to do this built into the VESC using maybe one of the two following commands?

case COMM_SET_POS:
    ind = 0;
    mc_interface_set_pid_pos((float)buffer_get_int32(data, &ind) / 1000000.0);
    timeout_reset();
    break;

case COMM_SET_HANDBRAKE:
    ind = 0;
    mc_interface_set_handbrake(buffer_get_float32(data, 1e3, &ind));
    timeout_reset();
    break;
WackoKacko commented 1 year ago

I'm actually trying to do something similar.