SETUP: I am using a Raspberry Pi Pico configured for the Arduino IDE using the Arduino-Pico library. I am using NEMA08-AMT112S series stepper motor that comes with an encoder. The driver is a standard L298N stepper driver board.
ISSUE: I am having issues moving to the motor target position. I have the motor target hard coded to a value of 3. However, when I run the following code, the motor moves for the initialization then holds itself at the zero position. The motor gets hot. I have it printing the motor angle and it says it is at 0. Without the motor driver being powered, the motor angle updates as I turn the motor shaft with my hands. What could be the cause of the issues?
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/adc.h"
#define P1_PLUS 18
#define P1_MINUS 19
#define P2_PLUS 20
#define P2_MINUS 21
#define EN1 26
#define EN2 27
#define A 14
#define B 15
// Stepper driver instance
StepperMotor motor = StepperMotor(50 , 5.4);
StepperDriver4PWM driver = StepperDriver4PWM(P1_PLUS, P1_MINUS, P2_PLUS, P2_MINUS, EN1, EN2);
// encoder instance
Encoder encoder = Encoder(A, B, 2048);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
// commander interface
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }
void setup() {
gpio_init(P1_PLUS); // Initialize GPIO
gpio_set_dir(P1_PLUS, GPIO_OUT); // Set as output
gpio_init(P1_MINUS); // Initialize GPIO
gpio_set_dir(P1_MINUS, GPIO_OUT); // Set as output
gpio_init(P2_PLUS); // Initialize GPIO
gpio_set_dir(P2_PLUS, GPIO_OUT); // Set as output
gpio_init(P2_MINUS); // Initialize GPIO
gpio_set_dir(P2_MINUS, GPIO_OUT); // Set as output
gpio_init(EN1); // Initialize GPIO
gpio_set_dir(EN1, GPIO_OUT); // Set as output
gpio_init(EN2); // Initialize GPIO
gpio_set_dir(EN2, GPIO_OUT); // Set as output
gpio_init(A); // Initialize GPIO
gpio_set_dir(A, GPIO_IN); // Set as output
gpio_init(B); // Initialize GPIO
gpio_set_dir(B, GPIO_IN); // Set as output
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SinePWM;
// power supply voltage [V]
driver.voltage_power_supply = 24;
driver.init();
driver.enable();
// link the motor to the driver
motor.linkDriver(&driver);
// Max DC voltage allowed - default voltage_power_supply
driver.voltage_limit = 24;
// set control loop type to be used
//motor.controller = MotionControlType::velocity_openloop;
motor.controller = MotionControlType::angle;
// controller configuration based on the control type
motor.PID_velocity.P = 0.1;
motor.PID_velocity.I = 10;
motor.PID_velocity.D = 0.00;
motor.PID_velocity.output_ramp = 5;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.1;
motor.current_limit = 1.6; // Amps - default 2 Amps
// angle loop controller
motor.P_angle.P = 2;
motor.P_angle.I = 0.5;
motor.P_angle.D = 0;
// angle loop velocity limit
motor.velocity_limit = 5;
Serial.begin(9600);
//driver.enable();
motor.useMonitoring(Serial);
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// define the motor id
command.add('M', onMotor, "motor");
motor.target = 0;
delay(1000);
}
void loop() {
motor.target = 3;
// iterative setting FOC phase voltage
motor.loopFOC();
motor.move();
}