Motor input from array


I am working on a robot leg project. So my motor need to follow certain trajectory. For example, one of my motor trajectory can be seen below.

I have thousand point from this trajectory. My plan is send this point to motor. So motor can fallow the trajectory. Before the send all data to motor. I wanted to do some test. I did some changing on open loop example but it is not working. Motor don’t fallow the given points. I couldn’t figure out what am I doing wrong. My code is;

 #include <SimpleFOC.h>

// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor(7);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

//target variable
float pos[] = {3,2,5,1,1.5,0.5,7};
int a = 0;
float tar = 0;

void setup() {

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
  // limit the maximal dc voltage the driver can set
  // as a protection measure for the low-resistance motors
  // this value is fixed on startup
  driver.voltage_limit = 6;
  // link the motor and the driver

  // limiting motor movements
  // limit the voltage to be set to the motor
  // start very low for high resistance motors
  // currnet = resistance*voltage, so try to be well under 1Amp
  motor.voltage_limit = 3;   // [V]
  // limit/set the velocity of the transition in between 
  // target angles
  motor.velocity_limit = 5; // [rad/s] cca 50rpm
  // open loop control config
  motor.controller = MotionControlType::angle_openloop;

  // init motor hardware

void loop() {
  // open  loop angle movements
  // using motor.voltage_limit and motor.velocity_limit
  for(a=0; a<5; a++)
  tar = pos[a];
if (a==5){
  // user communication;

Hi @Coskun,

You can’t really use delay in the main loop when doing motor control… you have to call move() very frequently, perhaps 1000x per second (1kHz) or faster.

If you call _delay(100); in your main loop, you will have at most 10 iterations per second, or 10Hz. This is much too slow.

You’ll have to find a more clever way to write this program, which does not use any delays, but still only updates the target value 10x per second. Hint: you can keep a timestamp and compare using the millis() function. Or you can compare motor.shaft_angle to the target value to see if you have reached the target.