working velocitiy closed loop (but slow?)
This commit is contained in:
parent
6bf5371d97
commit
d26f6e3478
@ -23,8 +23,8 @@ lib_archive = false
|
|||||||
# ;platform_packages = espressif/toolchain-xtensa-esp32@8.4.0+2021r2-patch5
|
# ;platform_packages = espressif/toolchain-xtensa-esp32@8.4.0+2021r2-patch5
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/simplefoc/Arduino-FOC.git#dev
|
https://github.com/schnilz/Arduino-FOC.git#dev
|
||||||
https://github.com/simplefoc/Arduino-FOC-drivers.git#dev
|
https://github.com/schnilz/Arduino-FOC-drivers.git#dev
|
||||||
# https://github.com/handmade0octopus/ESP32-TWAI-CAN
|
# https://github.com/handmade0octopus/ESP32-TWAI-CAN
|
||||||
https://github.com/tdk-invn-oss/motion.arduino.ICM42670P
|
https://github.com/tdk-invn-oss/motion.arduino.ICM42670P
|
||||||
; https://github.com/simplefoc/Arduino-FOC-dcmotor.git
|
; https://github.com/simplefoc/Arduino-FOC-dcmotor.git
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "SimpleFOCDrivers.h"
|
#include "SimpleFOCDrivers.h"
|
||||||
// #include "comms/streams/BinaryIO.h"
|
// #include "comms/streams/BinaryIO.h"
|
||||||
// #include "encoders/as5600/MagneticSensorAS5600.h"
|
// #include "encoders/as5600/MagneticSensorAS5600.h"
|
||||||
// #include "encoders/calibrated/CalibratedSensor.h"
|
#include "encoders/calibrated/CalibratedSensor.h"
|
||||||
// #include "encoders/esp32hwencoder/ESP32HWEncoder.h"
|
// #include "encoders/esp32hwencoder/ESP32HWEncoder.h"
|
||||||
|
|
||||||
#include "DRV8323S.hpp"
|
#include "DRV8323S.hpp"
|
||||||
@ -95,7 +95,7 @@ const int voltage_lpf = 50;
|
|||||||
// ESP32HWEncoder encoder =
|
// ESP32HWEncoder encoder =
|
||||||
// ESP32HWEncoder(ENC_A, ENC_B, 4096 / 4); // The Index pin can be omitted
|
// ESP32HWEncoder(ENC_A, ENC_B, 4096 / 4); // The Index pin can be omitted
|
||||||
Encoder encoder = Encoder(ENC_A, ENC_B, 4096 / 4);
|
Encoder encoder = Encoder(ENC_A, ENC_B, 4096 / 4);
|
||||||
// CalibratedSensor encoder_calibrated = CalibratedSensor(encoder);
|
CalibratedSensor encoder_calibrated = CalibratedSensor(encoder);
|
||||||
// MagneticSensorAS5600 encoder = MagneticSensorAS5600(0x36);
|
// MagneticSensorAS5600 encoder = MagneticSensorAS5600(0x36);
|
||||||
|
|
||||||
#ifdef MOTOR
|
#ifdef MOTOR
|
||||||
@ -236,30 +236,33 @@ void setup() {
|
|||||||
digitalWrite(INLABC, 1); // enable
|
digitalWrite(INLABC, 1); // enable
|
||||||
// driver.init(&SPI);
|
// driver.init(&SPI);
|
||||||
// status();
|
// status();
|
||||||
motor.linkDriver(drv8323s.focdriver);
|
|
||||||
motor.linkSensor(&encoder);
|
motor.linkSensor(&encoder);
|
||||||
|
motor.linkDriver(drv8323s.focdriver);
|
||||||
// motor.foc_modulation = FOCModulationType::SinePWM;
|
// motor.foc_modulation = FOCModulationType::SinePWM;
|
||||||
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
|
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
|
||||||
|
|
||||||
motor.voltage_sensor_align = 6;
|
motor.voltage_sensor_align = 3;
|
||||||
motor.voltage_limit = 3;
|
motor.voltage_limit = 5;
|
||||||
motor.controller = MotionControlType::velocity_openloop;
|
// motor.controller = MotionControlType::velocity_openloop;
|
||||||
|
motor.controller = MotionControlType::velocity;
|
||||||
// motor.controller = MotionControlType::torque;
|
// motor.controller = MotionControlType::torque;
|
||||||
// motor.torque_controller = TorqueControlType::voltage;
|
// motor.torque_controller = TorqueControlType::voltage;
|
||||||
|
motor.useMonitoring(SSYNCIF);
|
||||||
drv8323s.focdriver->voltage_power_supply = vdrive_read;
|
drv8323s.focdriver->voltage_power_supply = vdrive_read;
|
||||||
motor.init();
|
motor.init();
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
// // set voltage to run calibration
|
// // set voltage to run calibration
|
||||||
// encoder_calibrated.voltage_calibration = 3;
|
encoder_calibrated.voltage_calibration = 3;
|
||||||
// // Running calibration
|
// // Running calibration
|
||||||
// encoder_calibrated.calibrate(motor);
|
encoder_calibrated.calibrate(motor);
|
||||||
|
|
||||||
// //Serial.println("Calibrating Sensor Done.");
|
// //Serial.println("Calibrating Sensor Done.");
|
||||||
// // Linking sensor to motor object
|
// // Linking sensor to motor object
|
||||||
// motor.linkSensor(&encoder_calibrated);
|
// motor.linkSensor(&encoder_calibrated);
|
||||||
motor.initFOC();
|
motor.initFOC();
|
||||||
|
|
||||||
motor.move(1);
|
motor.move(0);
|
||||||
// sensor.init(&SPI);
|
// sensor.init(&SPI);
|
||||||
// motors[i].linkSensor(&sensors[i]);
|
// motors[i].linkSensor(&sensors[i]);
|
||||||
#endif
|
#endif
|
||||||
@ -393,6 +396,7 @@ void setup() {
|
|||||||
// esp_task_wdt_add(NULL); // add current thread to WDT watch
|
// esp_task_wdt_add(NULL); // add current thread to WDT watch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
#ifdef MOTOR
|
#ifdef MOTOR
|
||||||
// drv8323s.focdriver->voltage_power_supply = vdrive_read;
|
// drv8323s.focdriver->voltage_power_supply = vdrive_read;
|
||||||
@ -404,11 +408,20 @@ void loop() {
|
|||||||
motor.move();
|
motor.move();
|
||||||
#else
|
#else
|
||||||
encoder.update(); // optional: Update manually if not using loopfoc()
|
encoder.update(); // optional: Update manually if not using loopfoc()
|
||||||
|
#endif
|
||||||
|
if(i++ % 100 == 0) {
|
||||||
static float angle = 0;
|
static float angle = 0;
|
||||||
static float old_angle = 0;
|
static float old_angle = 0;
|
||||||
angle = encoder.getAngle();
|
angle = encoder.getAngle();
|
||||||
|
|
||||||
|
SSYNCIF.print("enc: ");
|
||||||
SSYNCIF.print(angle * 180.0 / 3.1415);
|
SSYNCIF.print(angle * 180.0 / 3.1415);
|
||||||
|
SSYNCIF.print("mec: ");
|
||||||
|
SSYNCIF.print(encoder.getMechanicalAngle() * 180.0 / 3.1415);
|
||||||
|
SSYNCIF.print("\tcal: ");
|
||||||
|
SSYNCIF.print(encoder_calibrated.getAngle() * 180.0 / 3.1415);
|
||||||
SSYNCIF.println();
|
SSYNCIF.println();
|
||||||
|
}
|
||||||
|
|
||||||
// inv_imu_sensor_event_t imu_event;
|
// inv_imu_sensor_event_t imu_event;
|
||||||
|
|
||||||
@ -435,7 +448,6 @@ void loop() {
|
|||||||
// delay(100);
|
// delay(100);
|
||||||
// // SSYNCIF.print("V: ");
|
// // SSYNCIF.print("V: ");
|
||||||
// // SSYNCIF.println(vdrive_read);
|
// // SSYNCIF.println(vdrive_read);
|
||||||
#endif
|
|
||||||
#ifdef MOTOR
|
#ifdef MOTOR
|
||||||
// SSYNCIF.print(" ");
|
// SSYNCIF.print(" ");
|
||||||
// uint16_t result = 0;
|
// uint16_t result = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user