Setup

Initialization functions and setup

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

Last updated

Was this helpful?