Motor control
These functions provide motor control without using effects from Feelix and are based on the SimpleFOC library. Visit simplefoc.com for more details.
This code works with the Feelix Effect Arduino Library
You can use the functions specified in the documentation of the simpleFOC library.
Get motor angle and velocity
/* when feelix.run() and feelix.move_feelix() or feelix.bldc->loopFOC()
* is called in the loop the angle can be directly accessed with:
*/
float angle // Radians
float angleDeg // Degrees
/* the velocity can be directly accessed with: */
float velocity
/* read value magnetic rotary encoder without using feelix.run()
* function is handled in feelix.run() no need to duplicate
*/
feelix.sensor->update();
feelix.sensor->getAngle();
feelix.sensor->getVelocity();
Control type options
/* motion control type can be updated at run time to alternate between different control types.
You only need to control these settings when writing your own custom effects with SimpleFOC */
feelix.bldc->controller = MotionControlType::torque;
feelix.bldc->controller = MotionControlType::angle;
feelix.bldc->controller = MotionControlType::velocity;
Move the motor
/* 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 to update torque, velocity, or angle
* depending on the set MotionControlType
*/
feelix.bldc->move(value);
Motor settings
/* set max velocity */
feelix.bldc->velocity_limit = 22;
/* set max voltage */
feelix.bldc->voltage_limit = 12;
PID controller settings (more information)
/* Set velocity PID settings */
feelix.bldc->PID_velocity.P = 0.5;
feelix.bldc->PID_velocity.I = 10.0;
feelix.bldc->PID_velocity.D = 0.0;
/* Set angle PID settings */
feelix.bldc->P_angle.P = 14.0;
feelix.bldc->P_angle.I = 0.0;
feelix.bldc->P_angle.D = 0.0;
For all possibilities, check out the complete documentation at SimpleFOC.com
Motor control functions in Feelix Library
Move the motor to a specific position, speed value is optional.
/* function to let the motor move towards specific angle (blocking code)
* angle: angle in degrees
* speed: percentage 0.0 - 0.1 of max velocity
* threshold: accuracy target position (degrees)
* default: stop within 0.2 degrees from target area
*/
feelix.move_to(float angle, float speed, float threshold);
/* returns is set to TRUE while moving to desired positoin,
* and FALSE when position is reached
*/
feelix.MOVING;
Last updated
Was this helpful?