Basic example: importing a velocity effect exported from Feelix and playing it in a loop. The example code in de library provides a more elaborate example with callback and alternating between modes.
/* the velocity effect is time based
* it will start to play using the .play(bool play, long time = millis())
* to start play = true
* to stop play = false
* time (optional)
*/
velocity_effect.play(true, (long) feelix.current_time);
Update velocity effect in the loop
/* read angle, velocity and direction
* this function needs to update at a high frequency */
feelix.run();
/* play velocity effect, call every loop to update values based on new angle */
feelix.playVelocityEffect(velocity_effect);
/* function to write the values of the effects to the motor */
feelix.move_feelix();
Putting it all together
#include "Feelix.h"
/* initialize Feelix */
Feelix feelix = Feelix();
/* initialize velocity effect */
EffectConfig_s velocity_effect_config {
.data_size = 39,
.angle = 1900.0,
.quality = 50,
.effect_type = Effect_type::NOTSET,
.control_type = Control_type::VELOCITY
};
float data_velocity_effect[] = {0.4, 0.421930712, 0.629039512, 0.894060032, 0.710566161, 0.779037123, 0.799908945, 0.760426118, 0.641906967, 0.440053119, 0.173911728, -0.112390448, -0.369818486, -0.568972266, -0.702936269, -0.776986255, -0.799999625, -0.769220739, -0.667949720, -0.488878603, -0.241135732, 0.036209555, 0.285494146, 0.466127080, 0.568262685, 0.599999234, 0.577934856, 0.505729440, 0.377929191, 0.200979469, 0.002474856, -0.175598100, -0.304512257, -0.377294017, -0.399998069, -0.370054414, -0.289393446, -0.166375320, -0.0};
FeelixEffect velocity_effect = FeelixEffect(velocity_effect_config, data_velocity_effect);
/* variables to read and print sensor data */
const uint8_t loop_interval = 50;
uint8_t loop_count = 0;
void setup() {
Serial.begin(115200);
feelix.init();
velocity_effect.infinite = true;
velocity_effect.play(true, (long) feelix.current_time);
delay(100);
}
void loop() {
/* read angle, velocity and direction
* this function needs to update at a high frequency without interruptions */
feelix.run();
/* functions within the loop that need to be called less frequently:
* adapt frequency with loop_interval
* E.g. for printing values and reading sensors;
*/
if (loop_count++ > loop_interval) {
loop_count = 0;
feelix.blinkStatusLED();
feelix.readTemperature();
/* print angle and velocity (values are updated in feelix.run()) */
Serial.println((String) feelix.angleDeg + "\t" + feelix.velocity + "\t" +
feelix.temp + "\t" + feelix.driverVoltage);
}
/* play velocity effect, call every loop to update values based on new angle */
feelix.playVelocityEffect(velocity_effect);
/* function to write the values of the effects to the motor */
feelix.move_feelix();
}