Skip to content

Feat hybridstepper to main #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "HybridStepperMotor.h"
#include "HybridStepperMotorOld.h"
#include "./communication/SimpleFOCDebug.h"

// HybridStepperMotor(int pp)
// HybridStepperMotorOld(int pp)
// - pp - pole pair number
// - R - motor phase resistance
// - KV - motor kv rating (rmp/v)
// - L - motor phase inductance [H]
HybridStepperMotor::HybridStepperMotor(int pp, float _R, float _KV, float _inductance)
HybridStepperMotorOld::HybridStepperMotorOld(int pp, float _R, float _KV, float _inductance)
: FOCMotor()
{
// number od pole pairs
@@ -27,13 +27,13 @@ HybridStepperMotor::HybridStepperMotor(int pp, float _R, float _KV, float _induc
/**
Link the driver which controls the motor
*/
void HybridStepperMotor::linkDriver(BLDCDriver *_driver)
void HybridStepperMotorOld::linkDriver(BLDCDriver *_driver)
{
driver = _driver;
}

// init hardware pins
int HybridStepperMotor::init()
int HybridStepperMotorOld::init()
{
if (!driver || !driver->initialized)
{
@@ -74,7 +74,7 @@ int HybridStepperMotor::init()
}

// disable motor driver
void HybridStepperMotor::disable()
void HybridStepperMotorOld::disable()
{
// set zero to PWM
driver->setPwm(0, 0, 0);
@@ -84,7 +84,7 @@ void HybridStepperMotor::disable()
enabled = 0;
}
// enable motor driver
void HybridStepperMotor::enable()
void HybridStepperMotorOld::enable()
{
// disable enable
driver->enable();
@@ -97,7 +97,7 @@ void HybridStepperMotor::enable()
/**
* FOC functions
*/
int HybridStepperMotor::initFOC()
int HybridStepperMotorOld::initFOC()
{
int exit_flag = 1;

@@ -132,7 +132,7 @@ int HybridStepperMotor::initFOC()
}

// Encoder alignment to electrical 0 angle
int HybridStepperMotor::alignSensor()
int HybridStepperMotorOld::alignSensor()
{
int exit_flag = 1; // success
SIMPLEFOC_DEBUG("MOT: Align sensor.");
@@ -226,7 +226,7 @@ int HybridStepperMotor::alignSensor()

// Encoder alignment the absolute zero angle
// - to the index
int HybridStepperMotor::absoluteZeroSearch()
int HybridStepperMotorOld::absoluteZeroSearch()
{

SIMPLEFOC_DEBUG("MOT: Index search...");
@@ -261,7 +261,7 @@ int HybridStepperMotor::absoluteZeroSearch()

// Iterative function looping FOC algorithm, setting Uq on the Motor
// The faster it can be run the better
void HybridStepperMotor::loopFOC()
void HybridStepperMotorOld::loopFOC()
{

// update sensor - do this even in open-loop mode, as user may be switching between modes and we could lose track
@@ -293,7 +293,7 @@ void HybridStepperMotor::loopFOC()
// It runs either angle, velocity or voltage loop
// - needs to be called iteratively it is asynchronous function
// - if target is not set it uses motor.target value
void HybridStepperMotor::move(float new_target)
void HybridStepperMotorOld::move(float new_target)
{

// set internal target variable
@@ -394,7 +394,7 @@ void HybridStepperMotor::move(float new_target)
}
}

void HybridStepperMotor::setPhaseVoltage(float Uq, float Ud, float angle_el)
void HybridStepperMotorOld::setPhaseVoltage(float Uq, float Ud, float angle_el)
{
angle_el = _normalizeAngle(angle_el);
float _ca = _cos(angle_el);
@@ -473,7 +473,7 @@ void HybridStepperMotor::setPhaseVoltage(float Uq, float Ud, float angle_el)
// Function (iterative) generating open loop movement for target velocity
// - target_velocity - rad/s
// it uses voltage_limit variable
float HybridStepperMotor::velocityOpenloop(float target_velocity)
float HybridStepperMotorOld::velocityOpenloop(float target_velocity)
{
// get current timestamp
unsigned long now_us = _micros();
@@ -509,7 +509,7 @@ float HybridStepperMotor::velocityOpenloop(float target_velocity)
// Function (iterative) generating open loop movement towards the target angle
// - target_angle - rad
// it uses voltage_limit and velocity_limit variables
float HybridStepperMotor::angleOpenloop(float target_angle)
float HybridStepperMotorOld::angleOpenloop(float target_angle)
{
// get current timestamp
unsigned long now_us = _micros();
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @file HybridStepperMotor.h
* @file HybridStepperMotorOld.h
*
*/

#ifndef HybridStepperMotor_h
#define HybridStepperMotor_h
#ifndef HybridStepperMotorOld_h
#define HybridStepperMotorOld_h

#include "Arduino.h"
#include "common/base_classes/FOCMotor.h"
@@ -17,17 +17,17 @@
/**
Stepper Motor class
*/
class HybridStepperMotor : public FOCMotor
class HybridStepperMotorOld : public FOCMotor
{
public:
/**
HybridStepperMotor class constructor
HybridStepperMotorOld class constructor
@param pp pole pair number
@param R motor phase resistance - [Ohm]
@param KV motor KV rating (1/K_bemf) - rpm/V
@param L motor phase inductance - [H]
*/
HybridStepperMotor(int pp, float R = NOT_SET, float KV = NOT_SET, float L = NOT_SET);
HybridStepperMotorOld(int pp, float R = NOT_SET, float KV = NOT_SET, float L = NOT_SET);

/**
* Function linking a motor and a foc driver
@@ -63,7 +63,7 @@ class HybridStepperMotor : public FOCMotor
void loopFOC() override;

/**
* Function executing the control loops set by the controller parameter of the HybridStepperMotor.
* Function executing the control loops set by the controller parameter of the HybridStepperMotorOld.
*
* @param target Either voltage, angle or velocity based on the motor.controller
* If it is not set the motor will use the target set in its variable motor.target
File renamed without changes.