simplefoc / Arduino-FOC-drivers

Drivers and support code for SimpleFOC
https://docs.simplefoc.com/drivers_library
MIT License
146 stars 63 forks source link

Add support for CalibratedSensor on Stepper Motors #18

Open c031917 opened 1 year ago

c031917 commented 1 year ago

I'd like to use the calibratedSensor on a stepper motor with:

MagneticSensorSPI sensor = MagneticSensorSPI(PA8, 14, 0x3FFF); 
// instantiate the calibrated sensor object
CalibratedSensor sensor_calibrated = CalibratedSensor(sensor);
StepperMotor motor = StepperMotor(50);
motor.linkSensor(&sensor_calibrated);

Currently only BLDCmotor is implemented.

I am not sure if just duplicating the code in CalibratedSensor.cpp and replacing

void CalibratedSensor::calibrate(BLDCMotor& motor){

by

void CalibratedSensor::calibrate(StepperMotor& motor){

and changing CalibratedSensor.h (add last line)

to:

#ifndef __CALIBRATEDSENSOR_H__
#define __CALIBRATEDSENSOR_H__

#include "common/base_classes/Sensor.h"
#include "BLDCMotor.h"
#include "StepperMotor.h"
#include "common/base_classes/FOCMotor.h"

class CalibratedSensor: public Sensor{

public:
    // constructor of class with pointer to base class sensor and driver
    CalibratedSensor(Sensor& wrapped);
    ~CalibratedSensor();

    /*
    Override the update function
    */
    virtual void update() override;

    /**
    * Calibrate method computes the LUT for the correction
    */
    virtual void calibrate(BLDCMotor& motor);
    virtual void calibrate(StepperMotor& motor);

is enough. The calculations about the electrical angles are for a BLDC motor, these might not fit to a stepper motor which has 90 degrees between its poles instead of 120 degrees.

May be somebody can provide the right calculations?