Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mlodzianck
Created May 22, 2021 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlodzianck/27a73a54b40c83d6ef6b59437cf80781 to your computer and use it in GitHub Desktop.
Save mlodzianck/27a73a54b40c83d6ef6b59437cf80781 to your computer and use it in GitHub Desktop.
// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
// BLDCMotor( pp number , phase resistance)
BLDCMotor motor = BLDCMotor(11 , 0.6);
BLDCDriver3PWM driver = BLDCDriver3PWM(25,26,27);
//target variable
float target_velocity = 2; // rad/s
// instantiate the commander
//Commander command = Commander(Serial);
void setup() {
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor current (provided resistance)
motor.current_limit = 12; // [Amps]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
// add target command T
Serial.begin(115200);
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// open loop velocity movement
// using motor.current_limit and motor.velocity_limit
motor.move(2);
// user communication
// command.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment