SimpleFOCStudio does nothing

  1. Install sucessfully (Ubuntu)
  2. Start motion application (source below)
  3. Click “Configure”, enter bitrate, enter “M” for command
  4. Click “Connect”, successful.
  5. Absolutely nothing. All fields are “0”. I tried “Pull Parmas”, “Enable”. Nothing does anything. No error messages to let me know what’s wrong.

Screenshot is below.

#include <Arduino.h>
#include <SimpleFOC.h>
#include “STM32HWEncoder.h”
#include <SimpleFOC.h>
#include “DRV8301.h”
#include “Wire.h”
#include “AS5600.h”
#include “core_cm4.h”

// ODESCV4_3 : F405+DRV8301
#define MOT1_AH  PA8
#define MOT1_BH  PA9
#define MOT1_CH  PA10
#define MOT1_AL PB13
#define MOT1_BL PB14
#define MOT1_CL PB15
#define MOT1_EN PB12
#define MOT1_FAULT PD2
#define MOT1_SO1 PC0
#define MOT1_SO2 PC1
#define MOT1_SO3 \_NC
#define MOT2_AH  PC6
#define MOT2_BH  PC7
#define MOT2_CH  PC8
#define MOT2_AL  PA7
#define MOT2_BL  PB0
#define MOT2_CL  PB1
#define MOT2_EN PB6
#define ENC1_A PB_4
#define ENC1_B PB_5
#define ENC1_Z PC_9
#define ENC2_A PB_6
#define ENC2_B PB_7
#define ENC2_Z PC_15
#define SPI_SCK PC10
#define SPI_MISO PC11
#define SPI_MOSI PC12
#define SPI_CS PC13
#define UART_RX PA0
#define UART_TX PA1

// motions parameters
#define CONTROL_TYPE (MotionControlType::velocity)
#define SUPPLY_V (12)
#define DRIVER_V_LIMIT (12)
#define MOTOR_V_LIMIT (2)
#define MOTOR_I_LIMIT (100.0)
#define MOTOR_VEL_LIMIT (333.0)
#define SENSOR_ALIGN_V (0.5)
#define MOTOR_PP (7)
#define MOTOR_RES (0.1)
#define MOTOR_K (2000)
#define MOTOR_IND (0.000010)
#define VEL_P (0.1)
#define VEL_I (0.5)
#define VEL_D (0.0)
#define VEL_R (0.0)
#define VEL_L (1000.0)
#define VEL_F (0.01)
#define ANG_P (200.0)
#define ANG_I (0.0)
#define ANG_D (0.0)
#define ANG_R (0.0)
#define ANG_L (133.0)
#define ANG_F (0.00)

STM32HWEncoder sensor = STM32HWEncoder(1024, ENC1_A, ENC1_B);

DRV8301 gate_driver = DRV8301(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MOT1_EN, MOT1_FAULT); // MOSI, MISO, SCLK, CS, EN_GATE, FAULT
BLDCMotor motor = BLDCMotor(MOTOR_PP, MOTOR_RES, MOTOR_K, MOTOR_IND); // uni motor
BLDCDriver3PWM driver = BLDCDriver3PWM(MOT1_AH, MOT1_BH, MOT1_CH, MOT1_EN);   // disco-STM32G431CB

// commander communication instance
Commander command = Commander(Serial);
void doTarget(char\* cmd) {command.scalar(&motor.target, cmd);}
void doLimit(char\* cmd) {command.scalar(&motor.voltage_limit, cmd);}
void doMotor(char\* cmd) { command.motor(&motor, cmd); }
void doInduct(char\* cmd) { command.scalar(&motor.phase_inductance, cmd); }
char msgbuf\[256\];

void setup() {
Serial.begin(921600); // WARNING: low value like 115200 cause distorted FOC

// for timer analysis
SimpleFOCDebug::enable(&Serial);
Serial.printf(“enter setup…\\n”);

sensor.init();

// driver config
// power supply voltage \[V\]
driver.voltage_power_supply = SUPPLY_V;
driver.voltage_limit = DRIVER_V_LIMIT;
driver.pwm_frequency = 25000;
driver.init();

// configure the DRV8301
gate_driver.begin(PWM_INPUT_MODE_3PWM, SHUNT_GAIN_10);
\_delay(100);
int reg1, reg2, reg3, reg4, fault;
gate_driver.get_regs(&reg1, &reg2, &reg3, &reg4);
fault = gate_driver.is_fault();
sprintf(msgbuf, “DRV8301: fault=%x, STATREG1=0x%.4x, STATREG2=0x%.4x, CTRLREG1=0x%.4x, CTRLREG2=0x%.4x”, fault, reg1, reg2, reg3, reg4);
Serial.println(msgbuf);

// link driver
motor.linkDriver(&driver);
// link current sense and the driver

//  motor.motion_downsample = 10;
// set the inital target value
motor.target = 0;
motor.useMonitoring(Serial);
motor.monitor_downsample = 0; // disable intially
motor.monitor_variables = \_MON_TARGET | \_MON_VOLT_Q | \_MON_VOLT_D | \_MON_CURR_Q | \_MON_CURR_D | \_MON_VEL | \_MON_ANGLE;  // monitor target velocity and angle

// initialise motor
// moduleation mode
motor.init();

// limts: MUST BE AFTER motor.init() to take effect
motor.voltage_sensor_align = SENSOR_ALIGN_V;
//motor.controller = MotionControlType::torque;
motor.controller = CONTROL_TYPE;
// default voltage_power_supply
motor.velocity_limit = MOTOR_VEL_LIMIT;
motor.voltage_limit = MOTOR_V_LIMIT;
motor.current_limit = MOTOR_I_LIMIT;

// Tune PID MUST BE AFTER motor.init() to take effect
motor.PID_velocity.P = VEL_P; motor.PID_velocity.I = VEL_I; motor.PID_velocity.D = VEL_D; motor.PID_velocity.output_ramp = VEL_R; motor.PID_velocity.limit = VEL_L;  motor.LPF_velocity.Tf = VEL_F;
motor.P_angle.P =     ANG_P;       motor.P_angle.I = ANG_I;      motor.P_angle.D = ANG_D;      motor.P_angle.output_ramp = ANG_R;      motor.P_angle.limit = ANG_L;     motor.LPF_angle.Tf = ANG_F;

motor.initFOC();

// subscribe motor to the commander
command.add(‘L’, doLimit, “voltage limit”);
command.add(‘M’,doMotor,“motor”);
command.verbose = VerboseMode::on_request;
Serial.printf(“setup complete…\\n”);
\_delay(1000);
}

void loop()
{
// iterative setting FOC phase voltage
motor.loopFOC();

// iterative function setting the outter loop target
motor.move();

// motor monitoring
motor.monitor();

// user communication
command.run();
}

I’ve spied on the serial commands sent by the PC, and the issue appears to be that i’t’s not pre-pending the “Command ID” (M in my case) to the command. IN my trace I see:

C

T

VP

VI

VD

But I think this should be:

MC

MT

MVP

MVI

MVD

Hey @sgordon777,

Did you put the M command to the studio in here?

No I was putting “M” in the conn ID field in the config dialog instead of the propper field :frowning: . All good now, thanks