Yes it works. This is the main loop:
void loop() {
_delay(100);
Serial.print(" :: ");
Serial.println(sensorSC60228.getAngle());
sensorSC60228.update();
}
All right, so that’s really good news. Let me try plugging in the first sensor. It has a 1 meter cable so that could be another reason why I didn’t get a signal, perhaps the cable, even though I used very high quality TP, may be too much for the sensor to handle. Or the magnet is too far. So many things could go wrong. Stay tuned. It could just be I need to shorten the cable. Now I have something to compare against.
Excellent news, the dev code worked without any changes. Let me post a small example we could add to the codebase. I suck at git so you may copy/paste or write your own example.
Well, time to celebrate.
// Open loop motor control example
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "encoders/sc60228/MagneticSensorSC60228.h"
BLDCMotor motor = BLDCMotor(1);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15, PB12);
MagneticSensorSC60228 sensorSC60228(PA4);
void setup() {
sensorSC60228.init();
driver.voltage_power_supply = 12;
driver.pwm_frequency = 15000;
driver.init();
motor.linkDriver(&driver);
motor.voltage_limit = 3; // [V]
motor.velocity_limit = 10; // [rad/s] cca 50rpm
motor.controller = MotionControlType::velocity_openloop;
motor.init();
Serial.begin(115200);
Serial.println("Motor ready!");
_delay(1000);
}
void loop() {
_delay(10);
Serial.print(">> ");
Serial.println(sensorSC60228.getAngle());
sensorSC60228.update();
motor.move(2);
}
Of course the real test would be using it in a closed loop but I’m too burned out. Tomorrow is another day.
@runger, thank you, excellent job. Also, thanks to @robotsmith for the document and suggestions.
Cheers,
Valentine