Skip to content

Commit 96fbe93

Browse files
committed
Merge branch 'feature/web_socket_live_mode' into develop
2 parents 53409f4 + 28bda08 commit 96fbe93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+497
-265
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ jobs:
2323
name: "Build examples"
2424
runs-on: ubuntu-latest
2525
strategy:
26+
fail-fast: false
2627
matrix:
2728
example:
2829
[
2930
AdafruitPCA9685,
30-
LiveMode,
31+
SerialLiveMode,
32+
WebSocketLiveMode,
3133
MultiplePCA9685,
3234
Show,
3335
StandardServoLib,
@@ -48,9 +50,8 @@ jobs:
4850
run: pip install --upgrade platformio
4951
- name: Build PlatformIO examples
5052
run: |
51-
pio ci examples/${{ matrix.example }} \
52-
--lib=. \
53-
--project-conf=examples/${{ matrix.example }}/platformio.ini
53+
cd examples/${{ matrix.example }}
54+
pio run
5455
lint:
5556
name: "Lint"
5657
runs-on: ubuntu-22.04

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.vscode/c_cpp_properties.json
44
.vscode/launch.json
55
.vscode/ipch
6+
examples/*/.vscode
7+
examples/*/.gitignore

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ Servo(id, callback, threshold);
6969
| id | byte | Unique servo ID as specified via the Add-on |
7070
| positions | const int[] | Exported positions per frame |
7171
| callback | void (byte, int) | Function to trigger when a servo is moved |
72-
| threshold | byte | Max allowed position diff (default=20) |
72+
| threshold | byte | Max allowed position diff (default=0 / no threshold handling) |
73+
74+
> Note: the threshold is also used to define the speed for moving a servo to its neutral position when stopping an animation.
7375
7476
### Callback Function
7577
@@ -183,12 +185,7 @@ myBlenderAnimation.live(stream);
183185

184186
> Note: the default mode can not be triggered as it is only handled internally.
185187
186-
When calling the `stop` method, it is possible to pass a delay in milliseconds. This delay will be used when the servos are moved to their neutral position during the stop mode. To get to the neutral position, the current position will either be increased or decreased by 1. The delay therefore controls how fast or smooth this movement will take place. The default value for this parameter is `20`.
187-
188-
```ino
189-
myBlenderAnimation.stop(); // Default reset speed applied
190-
myBlenderAnimation.stop(30); // Servos will reset slower
191-
```
188+
When calling the `stop` method, the threshold values of the animation's servos are considered to control how fast or smooth they are moving towards their neutral position. Keep in mind that the servos will not have a threshold value by default which results in the stop mode to immediately trigger the neutral position of the servos. A slower and safer movement can be achieved by setting the threshold values as low as possible with the actual animation still able to run properly.
192189

193190
To use the `live` method, we have to pass a stream instance which will be used for reading serial commands. For example, we can pass `Serial` if we want to use the standard USB connection of an Arduino compatible board:
194191

@@ -199,6 +196,8 @@ void setup() {
199196
}
200197
```
201198

199+
This library also comes with a `LiveStream` class which allows for a more generic way to listen to live commands. For example, it can be used as part of the web socket based live mode for which you can find a dedicated example [here](examples/WebSocketLiveMode).
200+
202201
To get the current animation mode, we can simply call the `getMode` method. This will return a `byte` representing one of the mode constants mentioned in the table above. We can then compare the return value to those constants to act according to the current mode:
203202

204203
```ino

examples/AdafruitPCA9685/AdafruitPCA9685.ino

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
// Using the namespace to have short class references (Animation and Servo)
1414
using namespace BlenderServoAnimation;
1515

16-
// Frames per second - see original Blender animation / ik.h
17-
#define FPS 30
18-
19-
// Total animation frames - see original Blender animation / ik.h
20-
#define FRAMES 100
21-
2216
// PWM driver instance to set PWM output
2317
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
2418

examples/AdafruitPCA9685/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Adafruit PCA9685
2+
3+
Using a PCA9685 PWM Servo Driver to animate 2 servos. The animation is based on the IK example of the Blender Servo Animation add-on which resembles a simple neck mechanism.
4+
5+
![test](../../images/arduino-nano-with-PCA9685.png)

examples/AdafruitPCA9685/ik.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
Seconds: 3
77
Bones: 2
88
Armature: Armature
9+
Scene: Scene
910
File: ik.blend
1011
*/
1112

1213
#include <Arduino.h>
1314

15+
const byte FPS = 30;
16+
const int FRAMES = 100;
17+
1418
// Servo ID: 0
15-
const int NeckLeft[100] PROGMEM = {
19+
const int NeckLeft[FRAMES] PROGMEM = {
1620
375, 376, 377, 380, 384, 387, 391, 396, 400, 403, 406, 408, 410, 410, 409, 406, 402, 396, 390, 382, 373, 364, 355, 346, 338, 330, 323, 318, 314, 311, 309, 307, 305, 305, 305, 305, 306, 307, 309, 311, 314, 317, 320, 323, 327, 331, 335, 339, 343, 347,
1721
351, 356, 360, 364, 369, 374, 380, 386, 392, 398, 404, 410, 415, 420, 425, 429, 432, 435, 436, 437, 437, 436, 435, 434, 432, 430, 428, 426, 423, 421, 418, 415, 412, 409, 406, 403, 400, 397, 394, 391, 388, 386, 384, 381, 380, 378, 377, 376, 375, 375,
1822
};
1923

2024
// Servo ID: 1
21-
const int NeckRight[100] PROGMEM = {
25+
const int NeckRight[FRAMES] PROGMEM = {
2226
375, 376, 379, 383, 388, 394, 401, 409, 417, 426, 434, 443, 450, 457, 463, 468, 471, 472, 471, 469, 466, 462, 457, 452, 447, 441, 437, 432, 428, 424, 420, 416, 411, 407, 402, 398, 394, 389, 384, 380, 375, 370, 366, 361, 356, 352, 347, 342, 337, 333,
2327
328, 324, 319, 315, 312, 309, 308, 307, 306, 306, 306, 307, 308, 309, 310, 311, 312, 313, 313, 313, 313, 314, 315, 316, 318, 320, 322, 324, 327, 329, 332, 335, 338, 341, 344, 347, 350, 353, 356, 359, 362, 364, 366, 369, 370, 372, 373, 374, 375, 375,
2428
};

examples/AdafruitPCA9685/platformio.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
[platformio]
2+
src_dir = ./
3+
14
[env]
25
lib_deps =
36
adafruit/Adafruit PWM Servo Driver Library@^2.4.1
7+
BlenderServoAnimation=symlink://../../
48

59
[env:uno]
610
board = uno

examples/LiveMode/platformio.ini

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/MultiplePCA9685/MultiplePCA9685.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
// Using the namespace to have short class references (Animation and Servo)
1414
using namespace BlenderServoAnimation;
1515

16-
// Frames per second - see original Blender animation / ik.h
17-
#define FPS 30
18-
19-
// Total animation frames - see original Blender animation / ik.h
20-
#define FRAMES 100
21-
2216
// PWM driver instances to set PWM output
2317
Adafruit_PWMServoDriver pwmA(0x40);
2418
Adafruit_PWMServoDriver pwmB(0x41);
@@ -36,12 +30,12 @@ struct servoMap {
3630
// Forward declare the callback as it will be referenced in the following array
3731
void setPWM(byte servoID, int position);
3832

39-
// Define an array of servo maps
33+
// Define an array of servo mapsf
4034
servoMap servoMaps[] = {
4135
// Servo attached to board A on channel 0
4236
{Servo(0, NeckLeft, setPWM), pwmA, 0},
4337

44-
// Servo attached to board A on channel 0
38+
// Servo attached to board B on channel 0
4539
{Servo(1, NeckRight, setPWM), pwmB, 0},
4640
};
4741

examples/MultiplePCA9685/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Multiple PCA9685
2+
3+
Using two PCA9685 PWM Servo Drivers to animate 2 servos. The animation is based on the IK example of the Blender Servo Animation add-on which resembles a simple neck mechanism.
4+
5+
Note that the A0 address jumper has to be soldered on the second driver board. This setup can easily be extended to animate up to 32 servos. If even more servos are needed, you can also add more driver boards to the chain.
6+
7+
![test](../../images/arduino-nano-with-2-PCA9685.png)

0 commit comments

Comments
 (0)