Skip to content

Commit 4ff807b

Browse files
author
askuric
committed
ready for the v2.2.2
1 parent 254db1c commit 4ff807b

File tree

12 files changed

+107
-53
lines changed

12 files changed

+107
-53
lines changed

_includes/js/custom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ var classProps = [
101101
"quadrature",
102102
"pullup",
103103
"voltage_limit",
104+
"current_limit",
104105
"voltage_power_supply",
106+
"controller",
105107
"index_search_velocity",
106108
"controller",
107109
"velocity_limit",

docs/simplefoc_library/reference/build_flags.md renamed to docs/simplefoc_library/cheatsheet/build_flags.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
layout: default
33
title: Build Flags
44
nav_order: 2
5-
permalink: /reference/build_flags
6-
parent: Reference
5+
permalink: /cheetsheet/build_flags
6+
parent: Options Cheat Sheet
77
grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
88
has_children: False
99
has_toc: False
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
layout: default
3+
title: Options Cheat Sheet
4+
nav_order: 9
5+
permalink: /options_cheetsheet
6+
parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
7+
has_children: True
8+
has_toc: False
9+
---
10+
11+
12+
# Options Cheat Sheet
13+
14+
Find in these pages a summary of library options and build flags for your reference.
15+
16+
## Options
17+
18+
[Commonly used options](cheetsheet/options_reference) of <span class="simple">Simple<span class="foc">FOC</span>library</span> objects.
19+
20+
## Build flags
21+
22+
[Build flags](cheetsheet/build_flags) control the way the compiler generates the code for <span class="simple">Simple<span class="foc">FOC</span>library</span>.
23+

docs/simplefoc_library/reference/options.md renamed to docs/simplefoc_library/cheatsheet/options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
layout: default
33
title: Options Reference
44
nav_order: 1
5-
permalink: /reference/options_reference
6-
parent: Reference
5+
permalink: /cheetsheet/options_reference
6+
parent: Options Cheat Sheet
77
grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
88
has_children: False
99
has_toc: False

docs/simplefoc_library/code/debug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parent: Writing the Code
77
grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
88
---
99

10-
# Debugging SimpleFOClibrary sketches
10+
# Debugging <span class="simple">Simple<span class="foc">FOC</span>library</span> sketches
1111

1212
So you hooked everything up, downloaded your sketch, applied power, and... nothing. Or another common scenario: motor jerks around and makes terrible sounds.
1313

docs/simplefoc_library/code/monitoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The monitoring function can output 7 different motor specific variables:
4848
- `target` - current target value, specific to the motion control used (either current [A], voltage [V], velocity [rad/s], or position [rad])
4949
- `voltage.q` - [V] - set voltage in q direction
5050
- `voltage.d` - [V] - set voltage in d direction
51-
- `current.q` - [mA] - measured current in q direction ( if current sense available )
51+
- `current.q` - [mA] - measured current in q direction ( if current sense available ) or estimated current if no current sense but provided phase resistance
5252
- `current.d` - [mA] - measured current in d direction ( if current sense available )
5353
- `shaft_velocity` - [rad/s] - motor velocity
5454
- `shaft_angle` - [rad] - motor position

docs/simplefoc_library/code/motion_control/closed_loop_control/torque_control/dc_current.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
6262

6363
// instantiate the commander
6464
Commander command = Commander(Serial);
65-
void doTarget(char* cmd) { command.variable(&motor.target, cmd); }
65+
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
6666

6767
void setup() {
6868

docs/simplefoc_library/code/motion_control/closed_loop_control/torque_control/foc_current.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
7373

7474
// instantiate the commander
7575
Commander command = Commander(Serial);
76-
void doTarget(char* cmd) { command.variable(&motor.target, cmd); }
76+
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
7777

7878
void setup() {
7979

docs/simplefoc_library/code/motion_control/open_loop/angle_openloop.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ motor.controller = MotionControlType::angle_openloop;
3939

4040
You can test this algorithm by running the examples in the `motion_control/open_loop_motor_control/` folder.
4141

42-
This control algorithm is very simple. User sets the target angle it wants to achieve <i>a<sub>d</sub></i>. The algorithm only subtracts the current angle <i>a<sub>c</sub></i> and the desired angle <i>a<sub>d</sub></i> to find the direction it needs to move and goes in that direction with the highest velocity possible `motor.velocity_limit`(max velocity). To set this velocity it uses the same algorithm as for [velocity open-loop control](velocity_openloop). It integrates the velocity it in time to find out what is the angle it needs to set to the motor <i>a<sub>c</sub></i> in order to achieve it. Then the maximal allowed voltage `motor.voltage_limit` is going to be applied in the direction of the <i>a<sub>c</sub></i> using `SinePWM` or `SpaceVector` modulation.
42+
This control algorithm is very simple. User sets the target angle it wants to achieve <i>a<sub>d</sub></i>. The algorithm only subtracts the current angle <i>a<sub>c</sub></i> and the desired angle <i>a<sub>d</sub></i> to find the direction it needs to move and goes in that direction with the highest velocity possible `motor.velocity_limit`(max velocity). To set this velocity it uses the same algorithm as for [velocity open-loop control](velocity_openloop). It integrates the velocity it in time to find out what is the angle it needs to set to the motor <i>a<sub>c</sub></i> in order to achieve it. Then the maximal allowed voltage `motor.voltage_limit` is going to be applied in the direction of the <i>a<sub>c</sub></i> using `SinePWM` or `SpaceVector` modulation.
43+
44+
```cpp
45+
// calculate the distance from the target
46+
d_angle = target_angle - past_angle;
47+
// constrain the distance with maximal allowable displacement
48+
d_angle = constrain(d_angle, -velocity_limit*d_time, velocity_limit*d_time)
49+
// calculate the next angle
50+
next_angle = past_angle + d_angle;
51+
```
4352

4453
## Configuration
4554
``` cpp
@@ -54,16 +63,36 @@ motor.velocity_limit = 20;
5463
motor.voltage_limit = 3; // Volts
5564
// or current - if phase resistance provided
5665
motor.current_limit = 0.5 // Amps
66+
67+
```
68+
69+
The angle open-loop control will (if not provided phase resistance) set the voltage to the motor equal to the `motor.voltage_limit`
70+
71+
```cpp
72+
voltage = voltage_limit; // Volts
5773
```
74+
This is very ineficeint, as for different motors with different phase resistances the same voltage values can produce wildly different currents.
75+
For gimbal motor, you can run it in the open loop with the voltage limits of 5-10 Volts and it will reach the currents of 0.5-2 amps as it has the pahse resistance from 5-15 Ohms. For drone motors, the voltage limits should stay very low, under 1 volt. Because they have pahse resisatnce of 0.05 to 0.2 Ohms.
5876

59-
This type of motion control is highly inefficient therefore try not to use to high value for `motor.voltage_limit`. We suggest you to provide the motor class with the `phase_resistance` value and set the `motor.current_limit` instead the voltage limit. This current might be surpassed but at least you will know an approximate current your motor is drawing. You can calculate the current the motor is going to be producing by checking the motor resistance `phase_resistance` and evaluating:
77+
### Current limiting approaches
78+
79+
We suggest you to provide the motor class with the `phase_resistance` value and set the `motor.current_limit` instead the voltage limit. This current might be surpassed but at least you will know an approximate current your motor is drawing. You can calculate the current the motor is going to be producing by checking the motor resistance `phase_resistance` and evaluating:
80+
```cpp
81+
voltage = current_limit * phase_resistance; // Amps
82+
```
83+
The best way to use this control strategy would be to provide both phase resistance value and KV rating of your motor. The the library would be able to calculate he back-emf voltage and much more precisely estimate the consumed current. And with the current and the back-emf current the library can set much more appropriate voltage to the motor.
6084
```cpp
61-
voltage_limit = current_limit * phase_resistance; // Amps
85+
voltage = current_limit*phase_resistance + desired_velocity/KV; // Amps
6286
```
6387

88+
### Velocity limit
89+
6490
The maximal velocity `motor.velocity_limit` value is going to determine how fast your motor goes in between positions. The higher the value the faster the transition. But since we are turning the motor in open-loop we will not be able to know if the motor can follow the velocity. So make sure to put the `velocity_limit` value that is achievable for your motor. Also beware that for higher velocities and more holding torque you will need to increase the `motor.voltage_limit` or `motor.current_limit` variable as well.
6591

92+
### Changing limits in real-time
93+
6694
Also, you can change the voltage limit `motor.voltage_limit` (`motor.current_limit`) and transition velocity `motor.velocity_limit` in real-time if you need this kind of behavior in your application.
95+
6796
## Position open-loop control example
6897
Here is one basic example of the velocity open-loop control with the complete configuration. The program will set the target position of `0 RAD` and maintain it, and the user can change the target position using serial terminal.
6998
```cpp
@@ -74,12 +103,11 @@ Here is one basic example of the velocity open-loop control with the complete co
74103
BLDCMotor motor = BLDCMotor(11);
75104
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
76105

77-
//target variable
78-
float target_position = 0;
79-
80106
// instantiate the commander
81107
Commander command = Commander(Serial);
82-
void doTarget(char* cmd) { command.variable(&target_position, cmd); }
108+
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
109+
void doLimitVolt(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
110+
void doLimitVelocity(char* cmd) { command.scalar(&motor.velocity_limit, cmd); }
83111

84112
void setup() {
85113

@@ -98,9 +126,13 @@ void setup() {
98126

99127
// init motor hardware
100128
motor.init();
129+
motor.initFOC();
101130

102131
// add target command T
103132
command.add('T', doTarget, "target angle");
133+
command.add('L', doLimitVolt, "voltage limit");
134+
command.add('V', doLimitVelocity, "velocity limit");
135+
104136

105137
Serial.begin(115200);
106138
Serial.println("Motor ready!");
@@ -109,9 +141,10 @@ void setup() {
109141
}
110142

111143
void loop() {
144+
motor.loopFOC();
112145
// open loop angle movements
113146
// using motor.voltage_limit and motor.velocity_limit
114-
motor.move(target_position);
147+
motor.move();
115148

116149
// user communication
117150
command.run();

docs/simplefoc_library/code/motion_control/open_loop/velocity_openloop.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,37 @@ next_angle = past_angle + target_velocity*d_time;
4848
You need to know the `target_velocity`, sample time `d_time` and past value of the angle `past_angle` you have set to the motor.
4949

5050
## Configuration
51+
There are only three main parameters of the velocity open-loop control
5152
```cpp
52-
// choose FOC modulation (optional) - default SinePWM
53-
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
53+
// choose FOC modulation (optional) - SinePWM or SpaceVectorPWM
54+
motor.foc_modulation = FOCModulationType::SinePWM;
5455

5556
// limiting voltage
5657
motor.voltage_limit = 3; // Volts
5758
// or current - if phase resistance provided
5859
motor.current_limit = 0.5 // Amps
5960
```
6061

61-
This type of motion control is highly inefficient therefore try not to use to high value for `motor.voltage_limit`. We suggest you to provide the motor class with the `phase_resistance` value and set the `motor.current_limit` instead the voltage limit. This current might be surpassed but at least you will know an approximate current your motor is drawing. You can calculate the current the motor is going to be producing by checking the motor resistance `phase_resistance` and evaluating:
62+
The velocity open-loop control will (if not provided phase resistance) set the voltage to the motor equal to the `motor.voltage_limit`
63+
64+
```cpp
65+
voltage = voltage_limit; // Volts
66+
```
67+
This is very ineficeint, as for different motors with different phase resistances the same voltage values can produce wildly different currents.
68+
For gimbal motor, you can run it in the open loop with the voltage limits of 5-10 Volts and it will reach the currents of 0.5-2 amps as it has the pahse resistance from 5-15 Ohms. For drone motors, the voltage limits should stay very low, under 1 volt. Because they have pahse resisatnce of 0.05 to 0.2 Ohms.
69+
70+
### Current limiting approaches
71+
72+
We suggest you to provide the motor class with the `phase_resistance` value and set the `motor.current_limit` instead the voltage limit. This current might be surpassed but at least you will know an approximate current your motor is drawing. You can calculate the current the motor is going to be producing by checking the motor resistance `phase_resistance` and evaluating:
6273
```cpp
63-
voltage_limit = current_limit * phase_resistance; // Amps
74+
voltage = current_limit * phase_resistance; // Amps
6475
```
76+
The best way to use this control strategy would be to provide both phase resistance value and KV rating of your motor. The the library would be able to calculate he back-emf voltage and much more precisely estimate the consumed current. And with the current and the back-emf current the library can set much more appropriate voltage to the motor.
77+
```cpp
78+
voltage = current_limit*phase_resistance + desired_velocity/KV; // Amps
79+
```
80+
81+
### Changing limits in real-time
6582

6683
Also, you can change the voltage/current limit in real-time if you need this kind of behavior in your application.
6784

@@ -75,15 +92,13 @@ Here is one basic example of the velocity open-loop control with the complete co
7592

7693
// BLDC motor & driver instance
7794
// BLDCMotor( pp number , phase resistance)
78-
BLDCMotor motor = BLDCMotor(11 , 12.5);
95+
BLDCMotor motor = BLDCMotor(11 , 12.5, 100);
7996
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
8097

81-
//target variable
82-
float target_velocity = 2; // rad/s
83-
8498
// instantiate the commander
8599
Commander command = Commander(Serial);
86-
void doTarget(char* cmd) { command.variable(&target_velocity, cmd); }
100+
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
101+
void doLimitCurrent(char* cmd) { command.scalar(&motor.current_limit, cmd); }
87102

88103
void setup() {
89104

@@ -102,9 +117,11 @@ void setup() {
102117

103118
// init motor hardware
104119
motor.init();
120+
motor.initFOC();
105121

106122
// add target command T
107123
command.add('T', doTarget, "target velocity");
124+
command.add('C', doLimitCurrent, "current limit");
108125

109126
Serial.begin(115200);
110127
Serial.println("Motor ready!");
@@ -113,10 +130,10 @@ void setup() {
113130
}
114131

115132
void loop() {
116-
133+
motor.loopFOC();
117134
// open loop velocity movement
118135
// using motor.current_limit and motor.velocity_limit
119-
motor.move(target_velocity);
136+
motor.move();
120137

121138
// user communication
122139
command.run();

0 commit comments

Comments
 (0)