Skip to content

Commit 913b67b

Browse files
authored
Merge pull request #5 from simplefoc/dev
Dev
2 parents 75b59ea + 653523a commit 913b67b

File tree

29 files changed

+1095
-388
lines changed

29 files changed

+1095
-388
lines changed

.jekyll-metadata

52.6 KB
Binary file not shown.

_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 = [

_sass/overrides.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ div.language-sh pre, div.language-sh code ,div.language-shell pre, div.languag
164164
.img100{
165165
height: 100px;
166166
}
167+
.img150{
168+
height: 150px;
169+
}
167170
.img200{
168171
height: 200px;
169172
}
@@ -201,6 +204,10 @@ div.language-sh pre, div.language-sh code ,div.language-shell pre, div.languag
201204
height:inherit;
202205
width: 100%;
203206
}
207+
.img150{
208+
height:inherit;
209+
width: 100%;
210+
}
204211
.img100{
205212
height:inherit;
206213
width: 100%;
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+
```

0 commit comments

Comments
 (0)