You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<blockquoteclass="info"><pclass="heading">New experimental feature (not recommended for beginners)</p>
17
+
This feature is still in its early stages and we are not 100% happy with the API of the implementation. We are open to suggestions and contributions, so if you have any ideas on how to improve it, please let us know.
18
+
19
+
</blockquote>
20
+
21
+
This section is for advanced users that want to implement their own custom motion control algorithms.
As all the other standard motion control approaches, the custom motion control approach is be executed in the motion control loop (`motor.move()`). This loop will calculate the target torque (current or voltage) to be applied to the motor using the underlying torque/FOC control loop (`motor.loopFOC()`) in order to achieve the desired motion.
30
+
31
+
To use the custom motion control loop, you need to set the `motor.controller` variable to `MotionControlType::custom`.
32
+
```cpp
33
+
// set FOC loop to be used
34
+
motor.controller = MotionControlType::custom;
35
+
```
36
+
37
+
You can find some examples in `examples/motion_control/custom_motion_control/` folder.
38
+
39
+
This `custom` motion control requires the user to provide their own implentation of the motion control:
40
+
41
+
```cpp
42
+
// custom motion control function
43
+
floatcustom_motion_control(FOCMotor& motor) {
44
+
// your code here
45
+
46
+
// ex. simple proportional position control
47
+
float error = motor->target - motor->shaft_angle;
48
+
float target_torque = 10*error;
49
+
50
+
// return the target torque to be applied to the motor
51
+
return target_torque;
52
+
}
53
+
```
54
+
55
+
And then link this callback function to the motor instance:
The custom motion control uses the `motor.target` variable as the desired user defied target entry, and the user can choose to respect or ignore the velocity limits `motor.velocity_limit`. The torque limits are enforeced by the underlying torque control loop, so they will be respected regardless if the
63
+
user chooses to use them in their custom control or not. (If the user code returns a target torque that is higher than the limits set by the user, the library is going to limit it to the set limits before applying it to the motor).
64
+
65
+
The units of the target variable is completely user defined, so it can represent any physical quantity that the user wants to control.
66
+
67
+
For example, if the user wants to implement a torque control in Newton-meters (Nm), the user can set the `motor.target` variable to represent the target torque in Nm.
68
+
69
+
```cpp
70
+
...
71
+
float Kt = 0.1; // torque constant in Nm/A
72
+
// custom motion control function
73
+
floatcustomTorqueControl(FOCMotor& motor) {
74
+
// convert the target from Nm to Amps using the torque constant
75
+
float target_in_Amps = motor->target / Kt;
76
+
// return the target torque to be applied to the motor
Here is one basic example implementing custom motion control with the voltage mode torque control. The custom motion control is a simple proportional position control, where the target torque is proportional to the error between the target angle and the current angle. The user can change the PID parameters in runtime using the commander interface. As well as the target angle or change the motion control strategy to the standard ones.
The <spanclass="simple">Simple<spanclass="foc">FOC</span>library</span> also gives you the possibility to implement your own custom control loop. This is an experimental feature and we are not yet 100% happy with the implementation, but we wanted to give you the possibility to try it out and give us feedback. The custom control mode allows you to implement any control loop you want, and link it to the library. This way you can use the library's functions for reading sensors, controlling the motor and so on, while implementing your own control strategy.
0 commit comments