Import Haptic Effect
Basic example: importing a haptic effect exported from Feelix and playing it in a loop.
Last updated
Was this helpful?
Basic example: importing a haptic effect exported from Feelix and playing it in a loop.
Last updated
Was this helpful?
Content can be exported in Feelix see . The code generated during export can be pasted in the .
/* initialize Effect */
EffectConfig_s zigzag_spring_config {
.data_size = 6, //number of data points
.angle = 100, //width of the effect
.quality = 20, //spacing between data points
//(angle / (data_size - 1))
.effect_type = Effect_type::INDEPENDENT,
.control_type = Control_type::TORQUE
};
float data_zigzag_spring[] = {1.0, 0.4, 0.8, 0.2, 0.6, 0.0};
FeelixEffect zigzag_spring = FeelixEffect(zigzag_spring_config, data_zigzag_spring);
/* Play haptic effect at 80.0 degree angle
value indicates left side value of the effect
zigzag_spring_config angle indicates the width of the effect
*/
feelix.playHapticEffectAtAngle(zigzag_spring, 80.0);
#include "Feelix.h"
/* initialize Feelix */
Feelix feelix = Feelix();
/* initialize Effect */
EffectConfig_s zigzag_spring_config {
.data_size = 6,
.angle = 100,
.quality = 20,
.effect_type = Effect_type::INDEPENDENT,
.control_type = Control_type::TORQUE
};
float data_zigzag_spring[] = {1.0, 0.4, 0.8, 0.2, 0.6, 0.0};
FeelixEffect zigzag_spring = FeelixEffect(zigzag_spring_config, data_zigzag_spring);
/* mirrored copy of the same effect */
FeelixEffect zigzag_spring_mirrored = FeelixEffect(zigzag_spring_config, data_zigzag_spring);
/* variables to read data and sensors without interrupting the loop */
const uint8_t loop_interval = 50;
volatile uint8_t loop_count = 0;
void setup() {
Serial.begin(115200);
feelix.init();
/* mirror copied effect spring effect down to create inverse effect */
zigzag_spring_mirrored.position.y = -1.0;
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;
/* blink pink LED */
feelix.blinkStatusLED();
/* read motor temperature, shut down in case temperature exceeds 65.00 degrees */
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 + "\t");
}
/* example of a haptic effect
function needs to run every loop in order to be played
zigzag_spring positioned between x1:80 and x2:180 degrees
zigzag_spring_mirrored positioned between x1:180 and x2:280 degrees */
feelix.playHapticEffectAtAngle(zigzag_spring, 80.0);
feelix.playHapticEffectAtAngle(zigzag_spring_mirrored, 180.0);
/* function to write the values of the effects to the motor */
feelix.move_feelix();
}