Skip to content

Commit 44e9881

Browse files
committed
prepareation for the v2.2.1
1 parent 94fd755 commit 44e9881

File tree

13 files changed

+557
-570
lines changed

13 files changed

+557
-570
lines changed

_includes/js/custom.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var libraires =[
22
"SimpleFOC.h",
33
"PciManager.h",
44
"PciListenerImp.h",
5+
"ESP32Encoder.h",
56
"Encoder.h",
67
"FOCutils.h",
78
"BLDCMotor.h",
@@ -80,7 +81,8 @@ var classNames = [
8081
"InlineCurrentSense",
8182
"CurrentSense",
8283
"StepDirListener",
83-
"Commander"
84+
"Commander",
85+
"GenericSensor"
8486
];
8587

8688
var classProps = [
@@ -162,7 +164,10 @@ var funcNames = [
162164
"add",
163165
"pid",
164166
"lpf",
165-
"scalar"
167+
"scalar",
168+
"motion",
169+
"target",
170+
"motor"
166171

167172
];
168173
var structNames = [
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
layout: default
3+
title: Custom commands
4+
nav_order: 6
5+
permalink: /commander_custom
6+
parent: Commander Interface
7+
grand_parent: Communication
8+
grand_grand_parent: Writing the Code
9+
grand_grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
10+
---
11+
12+
# Extending commander with custom functionality
13+
14+
To extend the commander interface with your own functionality that has not been implemented by the <span class="simple">Simple<span class="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+
void myFunc(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"));
79+
_delay(1000);
80+
}
81+
82+
83+
void loop() {
84+
85+
// user communication
86+
command.run();
87+
_delay(10);
88+
}
89+
```
90+
91+
Then in your serial terminal you can just
92+
```sh
93+
$ ? # list the commands
94+
L: led on/off
95+
A: analog read A0-A4
96+
$ L0 # led off
97+
$ A1 # read A1
98+
321
99+
$ A3 # read A3
100+
1023
101+
$ L1 # led on
102+
$ L0 # led off
103+
```

docs/simplefoc_library/code/communication/commander/index.md

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ parent: Communication
77
grand_parent: Writing the Code
88
grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
99
has_children: true
10+
has_toc: false
1011
---
1112

1213
# Commander interface
@@ -17,7 +18,14 @@ Commander is a simple and flexible interface monitoring, supervision, configurat
1718
<img src="extras/Images/cmd_motor_get.gif" class="img100">
1819

1920
This g-code like interface provides callback to configure and tune any:
20-
- [BLDC or Stepper motor](commander_motor)
21+
- [PID controllers](commander_pid)
22+
- [Low pass filters](commander_lpf)
23+
- [Scalar variables](commander_scalar)
24+
- [Motion control](commander_target) <b><i>NEW</i>📢</b>
25+
- 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
2129
- PID controllers
2230
- Low pass filters
2331
- Motion control
@@ -27,13 +35,9 @@ This g-code like interface provides callback to configure and tune any:
2735
- sensor offsets
2836
- phase resistance
2937
- ...
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)
3538

3639
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)
3741

3842
## What happens when user sends a command?
3943
When the commander received the string:
@@ -135,11 +139,13 @@ void doSomething(char* cmd){ ... }
135139
With this simple interface you can create your own commands very simply and subscribe them to the `Commander` using just one line of code.
136140
137141
In addition to this flexible interface for adding generic callbacks the `Commander` class additionally implements standardized callbacks for:
138-
- BLDC motor (`BLDCMotor`) - `commander.motor(&motor, cmd)`
139-
- Stepper motor (`StepperMotor`) - `commander.motor(&motor, cmd)`
140-
- PID controller (`PIDController`) - `commander.pid(&pid, cmd)`
141-
- Low pass filter (`LowPassFilter`) - `commander.lpf(&lpf, cmd)`
142-
- Any numeric variable (`float`) - `commander.scalar(&variable, cmd)`
142+
- BLDC (`BLDCMotor`) or Stepper (`StepperMotor`) motor - `commander.motor(&motor, cmd)` - [see more](commander_motor)
143+
- PID controller (`PIDController`) - `commander.pid(&pid, cmd)` - [see more](commander_pid)
144+
- Low pass filter (`LowPassFilter`) - `commander.lpf(&lpf, cmd)` - [see more](commander_lpf)
145+
- Any numeric variable (`float`) - `commander.scalar(&variable, cmd)` - [see more](commander_scalar)
146+
- Target setting control (`BLDCMotor` or `StepperMotor`) - `commander.target(&motor, cmd)` - [see more](commander_target)
147+
- Full motion control (`BLDCMotor` or `StepperMotor`) - `commander.motion(&motor, cmd)` - [see more](commander_target)
148+
143149
144150
For example if you are interested in full configuration of one `motor` your code could look something like this:
145151
```cpp
@@ -168,13 +174,13 @@ Commander commander = ....
168174
// defined wrappers for generic callbacks
169175
void onPid(char* cmd){commander.pid(&motor.PID_velocity, cmd);}
170176
void onLpf(char* cmd){commander.lpf(&motor.LPF_velocity, cmd);}
171-
void onTarget(char* cmd){commander.scalar(&motor.tagret, cmd);}
177+
void onTarget(char* cmd){commander.target(&motor, cmd);}
172178

173179
void setup(){
174180
...
175181
commander.add('C',onPid,"PID vel");
176182
commander.add('L',onLpf,"LPF vel");
177-
commander.add('T',onTarget,"target vel");
183+
commander.add('T',onTarget,"target vel (+ torque limit)");
178184
...
179185
}
180186
void loop(){
@@ -187,19 +193,7 @@ This simple interface provides the user a simple way to make communicate and con
187193
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.
188194
189195
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
203197
When using the `Commander` in your program the user will have three built-in default commands he can use:
204198
- `?` - list all the commands available
205199
- `#` - get/set decimal point number
@@ -231,6 +225,26 @@ P: some pid
231225
R: some other motor
232226
```
233227

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+
234248
## *Simple**FOC**Studio* by [@JorgeMaker](https://github.com/JorgeMaker)
235249

236250
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

Comments
 (0)