Import Effects

Initialize an exported effect

The code generated during export can be pasted in the FeelixEffect library.

Additionally, the motor has to be initialized as shown here.

#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);

Play an exported haptic effect

void setup() {

  Serial.begin(115200);
 
  feelix.init();

  delay(100);

}

void loop() {
  
  /* read angle, velocity and direction */
  feelix.run();

  /* functions within the loop that need to be called less frequently: 
   * adapt frequency by adjusting the variable loop_interval
   * E.g., if statement can be used 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);
   
  /* write value to motors */
  feelix.move_feelix();
}

Play an exported velocity effect

/* 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);

void setup() {

  Serial.begin(115200);

  feelix.init();
  
  delay(100);
  
  velocity_effect.start(); // start the effect
}

void loop() {
  /* these functions need to update at a high frequency */
  
  /* read angle, velocity, direction and time */
   feelix.run();

  /* get the values based on current time*/
   feelix.playVelocityEffect(velocity_effect);

  /* write value to motors */
   feelix.move_feelix();
}

Access variables motor

The feelix.run() updates the following variables that can be accessed in the code:

The current angle of the motor in radians (float)

feelix.angle 

The velocity of the motor in rad/s (float)

feelix.velocity

The time since the program started is saved in (long) current_time, the time can be reset when the (long) start_time variable is set to millis()

feelix.current_time
feelix.start_time = millis();

Get the direction in which the motor is rotating, clockwise (1) and counterclockwise (-1).

feelix.rotation_dir

Change sensor direction opposed to motor direction

feelix.sensor_dir = Direction::CCW  /* default: Direction::CW */

Change effect settings

Enable effect (effects are enabled by default)

effect.enable();

Disable effect

effect.disable();

Check if an effect is enabled

/* variable will be true when enabled, false when disabled */
effect.enabled 

Start velocity effect

effect.start();

Stop velocity effect

effect.stop();

Change scale

scale.x changes the angle (position/torque effects) or the duration (velocity), and scale.y changes the intensity (voltage %), velocity (velocity %), or degrees. Depending on the type of effect (torque, position, velocity over time, or angle over time)

effect.scale.x = 1.5; /* default is 1.0 */
effect.scale.y = 0.5; /* default is 1.0 */

Loop velocity effect

effect.infinite = true; /* default is false */

Repeat a haptic effect every rotation

feelix.range = 360 /* repeat effect every 360 degrees (default) */
effect.infinite = true; /* default is false */

Disable effect in clockwise direction or counterclockwise direction (haptic only)

effect.direction.cw = false; /* default is true */
effect.direction.ccw = false; /* default is true */

Last updated

Was this helpful?