Feelix
  • Feelix Documentation
  • Getting started
    • Designing Effects
      • Torque Effects
      • Position Effects
      • Velocity Effects
      • (In)dependent Effects
    • Effect Library
    • Creating Collections
  • Create and edit
    • Edit tools
    • Effect Settings
    • Layers
    • Grid
    • Export Effects
    • TensorFlow
  • Connecting with Feelix
    • Setting up STM32
    • Setting up ESP32
    • Connect and Upload
    • Hardware Settings
    • Troubleshooting Feelix
  • Hardware support
    • Hardware
    • PCB pinout
    • Setup
    • Dependencies
    • FeelixEffect Docs
      • Functions and Parameters
      • Setup
      • Motor control
      • Import Effects
        • Import Haptic Effect
        • Import Velocity Effect
      • I2C communication
        • One Way Communication
        • Two Way Communication
  • Downloads
    • Feelix Design Tool
    • Feelix Arduino Library
    • 3D Models
    • Old Library Releases
Powered by GitBook
On this page

Was this helpful?

  1. Hardware support
  2. FeelixEffect Docs

Setup

Initialization functions and setup

PreviousFunctions and ParametersNextMotor control

Last updated 17 hours ago

Was this helpful?

This code works with the

#include "Feelix.h"

/* initialize Feelix */
Feelix feelix = Feelix();

/* variables to read data and sensors  
   without interrupting the loop every time */
const uint8_t loop_interval = 50;
uint8_t loop_count = 0;
void setup() {

  Serial.begin(115200);
  
  /* Copy zero_electric_angle and sensor_direction from the microcontroller settings window in Feelix to avoid performing motor calibration.
   * Set variables before feelix.init() as this function will start the calibration when values are unknown.
   */
  //feelix.bldc->sensor_direction = Direction::CCW;
  //feelix.bldc->zero_electric_angle = 1.7134552001953125;
  feelix.init();
  
  /* change the rotational direction of the sensor in relation to the motor
   * different from feelix.bldc->sensor_direction which is set during calibration
   */
  feelix.sensor_dir = Direction::CCW;
    
  delay(100);
}
void loop() {
    
  /* read angle, velocity and direction
   * the faster you can run it the better  */
  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;

    /* print angle and velocity */
    Serial.println((String) "Angle: " + feelix.angle + "\tAngleDeg: " + 
                    feelix.angleDeg + "\tVelocity:" + feelix.velocity);
  }
  
  /* SimpleFOC function - running the low level torque control loop
   * it sets the appropriate voltages to the phase pwm signals
   * the faster you can run it the better 
   */
  feelix.bldc->loopFOC();

  /* SimpleFOC function makes the motor move at 4 rad/s 
   * since MotionControlType is set to velocity 
   * the faster you can run it the better 
   */
  feelix.bldc->move(target_velocity);  
  
}
Feelix Effect Arduino Library