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
To extend the commander interface with your own functionality that has not been implemented by the <spanclass="simple">Simple<spanclass="foc">FOC</span>library</span> you only really need to:
15
+
1. implement your callback function `void myFunc(char*){}`
16
+
2. add it to the commander `commander.add('.',myFunc,"..")`
17
+
18
+
```cpp
19
+
voidmyFunc(char*){
20
+
// do something useful
21
+
}
22
+
23
+
Commander commander = Commander(...)
24
+
void setup(){
25
+
...
26
+
commander.add('A',myFunc,"my functionality");
27
+
...
28
+
}
29
+
void loop(){
30
+
...
31
+
commander.run()
32
+
}
33
+
```
34
+
35
+
## Example
36
+
37
+
This is an example code of extending the commander interface with two new functionalities, turning on and off a led light and reading 5 analog pins.
38
+
```cpp
39
+
40
+
#include <SimpleFOC.h>
41
+
42
+
// instantiate the commander
43
+
Commander command = Commander(Serial);
44
+
45
+
// led control function
46
+
void doLed(char* cmd){
47
+
if(atoi(cmd)) digitalWrite(LED_BUILTIN, HIGH);
48
+
else digitalWrite(LED_BUILTIN, LOW);
49
+
};
50
+
// get analog input
51
+
void doAnalog(char* cmd){
52
+
if (cmd[0] == '0') Serial.println(analogRead(A0));
53
+
else if (cmd[0] == '1') Serial.println(analogRead(A1));
54
+
else if (cmd[0] == '2') Serial.println(analogRead(A2));
55
+
else if (cmd[0] == '3') Serial.println(analogRead(A3));
56
+
else if (cmd[0] == '4') Serial.println(analogRead(A4));
57
+
};
58
+
59
+
void setup() {
60
+
// define pins
61
+
pinMode(LED_BUILTIN, OUTPUT);
62
+
pinMode(A0, INPUT);
63
+
pinMode(A1, INPUT);
64
+
pinMode(A2, INPUT);
65
+
pinMode(A3, INPUT);
66
+
pinMode(A4, INPUT);
67
+
68
+
// Serial port to be used
69
+
Serial.begin(115200);
70
+
71
+
// add new commands
72
+
command.add('L', doLed, "led on/off");
73
+
command.add('A', doAnalog, "analog read A0-A4");
74
+
75
+
Serial.println(F("Commander listening"));
76
+
Serial.println(F(" - Send ? to see the node list..."));
77
+
Serial.println(F(" - Send L0 to turn the led off and L1 to turn it off"));
78
+
Serial.println(F(" - Send A0-A4 to read the analog pins"));
- Setting target values and limits at once (ex. angle velocity torque)
26
+
- Changing the motion and torque control mode
27
+
- Enable/Disable the motor
28
+
-[Fully integrated configuration](commander_motor) for BLDC or Stepper motors
21
29
- PID controllers
22
30
- Low pass filters
23
31
- Motion control
@@ -27,13 +35,9 @@ This g-code like interface provides callback to configure and tune any:
27
35
- sensor offsets
28
36
- phase resistance
29
37
- ...
30
-
-[PID controllers](commander_pid)
31
-
-[Low pass filters](commander_lpf)
32
-
-[Scalar variables](commander_scalar)
33
-
-[Motion control target](commander_target) <b><i>NEW</i>📢</b>
34
-
- Setting target values and limits at once (ex. angle velocity torque)
35
38
36
39
Furthermore commander enables you to easily create your own commands and extend this interface in any way you might need for your particular application.
40
+
Here is the link to the docs about how to [make your custom commands.](commander_custom)
commander.add('T',onTarget,"target vel (+ torque limit)");
178
184
...
179
185
}
180
186
void loop(){
@@ -187,19 +193,7 @@ This simple interface provides the user a simple way to make communicate and con
187
193
It also makes the tuning of the custom control loops much easier since you can close the loop with a pid controller `PIDController` very easily and just add it to the commander to tune it in real time.
188
194
189
195
You can find more examples in library examples `examples/utils/communication_test/commander` folder.
190
-
191
-
## List of commands
192
-
193
-
All built-in commands and subcommands are defined in the library source, in file `src/communication/commands.h`.
194
-
If you wish to change the character id of a certain command that is the place to do it. 😄
195
-
196
-
In general we can separate the commands into:
197
-
- [Commander commands](#commander-commands) - commands specific for the `Commander` class
198
-
- [PID commands](#pid-commands) - commands specific for the `PIDController` class
199
-
- [Low pass filter commands](#low-pass-filter-commands) - commands specific for the `LowPassFilter` class
200
-
- [Motor commands](#motor-commands) - commands specific for the `FOCMotor` classes
201
-
202
-
### Commander commands
196
+
## Commander commands
203
197
When using the `Commander` in your program the user will have three built-in default commands he can use:
204
198
- `?` - list all the commands available
205
199
- `#` - get/set decimal point number
@@ -231,6 +225,26 @@ P: some pid
231
225
R: some other motor
232
226
```
233
227
228
+
229
+
## List of available commands
230
+
231
+
All built-in commands and subcommands are defined in the library source, in file `src/communication/commands.h`.
232
+
If you wish to change the character id of a certain command that is the place to do it. 😄
233
+
234
+
In general we can separate the commands into:
235
+
-[Commander commands](#commander-commands) - commands specific for the `Commander` class
236
+
-[PID commands](commands_pid) - commands specific for the `PIDController` class
237
+
-[Low pass filter commands](command_lpf) - commands specific for the `LowPassFilter` class
238
+
-[Motor commands](command_motor) - commands specific for the `FOCMotor` classes
239
+
240
+
When adding the `scalar` variable to the commander or the motion control `target` the only command letter used is the one provided to the `commander.add`.
241
+
-[Scaler variable](commander_scalar) - adding the scalar `float` variable
242
+
-[Motion control and target setting](commander_target) - setting the target for the `FOCMotor` classes
243
+
244
+
Commander provides a very simple way to extend the command list and implement new ones
245
+
-[Custom commands](commander_custom) - create your own callbacks
246
+
247
+
234
248
## *Simple**FOC**Studio* by [@JorgeMaker](https://github.com/JorgeMaker)
235
249
236
250
SimpleFOCStudio is an awesome application built by [@JorgeMaker](https://github.com/JorgeMaker) which we will try to keep up to date with out library. It is a python application that uses commander interface for tunning and configuring the motor.
0 commit comments