681浏览
查看: 681|回复: 26

[项目] 【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4

[复制链接]
37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图3

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图4


驴友花雕  中级技神
 楼主|

发表于 2024-7-5 11:00:28

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple ...

八、INA240电流传感器测试
● 使用Arduino IDE打开资料里面的电流测试程序 ,“angle_control_current_sense_test”,点击“上传”。

位置/角度运动控制示例
*步骤:
*1)配置电机和磁传感器
*2)运行代码
*3)从串行终端设置目标角度(弧度)

运行程序,电机会来回转动,打开串口监视器,可以监测电机的A相、B相的电流以及电流幅值。用手转动电机,电流值会发生改变。


【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  项目程序之三:INA240电流传感器测试,位置/角度运动控制

实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  4.   项目程序之三:INA240电流传感器测试,位置/角度运动控制
  5. */
  6. #include <SimpleFOC.h>
  7. // magnetic sensor instance - SPI
  8. //MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 10);
  9. // magnetic sensor instance - MagneticSensorI2C
  10. MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
  11. // magnetic sensor instance - analog output
  12. //MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);
  13. //无刷直流电机和驱动器实例
  14. BLDCMotor motor = BLDCMotor(7);
  15. BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
  16. // Stepper motor & driver instance
  17. //StepperMotor motor = StepperMotor(50);
  18. //StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);
  19. // 电流传感器
  20. // shunt resistor value
  21. // gain value
  22. // 引脚相位A、B(C可选)
  23. InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, _NC, A2);
  24. // 角度设定点变量
  25. float target_angle = 0;
  26. // instantiate the commander
  27. //Commander command = Commander(Serial);
  28. //void doTarget(char* cmd) { command.scalar(&target_angle, cmd); }
  29. void setup() {
  30.   // 初始化电流感应
  31.   current_sense.init();
  32.   // for SimpleFOCShield v2.01/v2.0.2
  33.   current_sense.gain_b *= -1;
  34.   // 初始化磁传感器硬件
  35.   sensor.init();
  36.   // 将电机连接到传感器
  37.   motor.linkSensor(&sensor);
  38.   // 驱动程序配置
  39.   // power supply voltage [V]
  40.   driver.voltage_power_supply = 24;
  41.   driver.init();
  42.   //连接电机和驱动器
  43.   motor.linkDriver(&driver);
  44.   // 选择FOC调制(可选)
  45.   motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
  46.   // 设置要使用的运动控制回路
  47.   motor.controller = MotionControlType::angle;
  48.   // 控制器配置
  49.   // default parameters in defaults.h
  50.   // 速度PI控制器参数
  51.   motor.PID_velocity.P = 0.2;
  52.   motor.PID_velocity.I = 2;
  53.   motor.PID_velocity.D = 0;
  54.   //设置给电机的最大电压
  55.   motor.voltage_limit = 1;
  56.   //速度低通滤波时间常数
  57.   //越低过滤越少
  58.   motor.LPF_velocity.Tf = 0.01;
  59.   // 角度P控制器
  60.   motor.P_angle.P = 5;
  61.   //位置控制的最大速度
  62.   motor.velocity_limit = 20;
  63.   // 使用串行监控
  64.   Serial.begin(115200);
  65.   // comment out if not needed
  66.   //motor.useMonitoring(Serial);
  67.   // 初始化电机
  68.   motor.init();
  69.   // 对齐传感器并启动FOC
  70.   motor.initFOC();
  71.   // 添加目标命令T
  72.   //command.add('T', doTarget, "target angle");
  73.   Serial.println(F("电机准备就绪!"));
  74.   Serial.println(F("使用串行终端设置目标角度:"));
  75.   Serial.println("电流感应就绪!");
  76.   _delay(1000);
  77. }
  78. void loop() {
  79.   // 主要FOC算法功能
  80.   // the faster you run this function the better
  81.   // Arduino UNO loop  ~1kHz
  82.   // Bluepill loop ~10kHz
  83.   motor.loopFOC();
  84.   // 运动控制功能
  85.   // 速度、位置或电压(在电机控制器中定义)
  86.   // this function can be run at much lower frequency than loopFOC() function
  87.   // You can also use motor.move() and set the motor.target in the code
  88.   motor.move(target_angle);
  89.   // function intended to be used with serial plotter to monitor motor variables
  90.   // significantly slowing the execution down!!!!
  91.   // motor.monitor();
  92.   // user communication
  93.   // command.run();
  94.   PhaseCurrent_s currents = current_sense.getPhaseCurrents();
  95.   float current_magnitude = current_sense.getDCCurrent();
  96.   Serial.print(currents.a * 1000); // milli Amps
  97.   Serial.print("\t");
  98.   Serial.print(currents.b * 1000); // milli Amps
  99.   Serial.print("\t");
  100.   Serial.print(currents.c * 1000); // milli Amps
  101.   Serial.print("\t");
  102.   Serial.println(current_magnitude * 1000); // milli Amps
  103.   _delay(1000);
  104. }
复制代码



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-5 11:15:36

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  4.   项目程序之三:INA240电流传感器测试,位置/角度运动控制
  5. */
  6. #include <SimpleFOC.h>
  7. // magnetic sensor instance - SPI
  8. //MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 10);
  9. // magnetic sensor instance - MagneticSensorI2C
  10. MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
  11. // magnetic sensor instance - analog output
  12. //MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);
  13. //无刷直流电机和驱动器实例
  14. BLDCMotor motor = BLDCMotor(7);
  15. BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
  16. // Stepper motor & driver instance
  17. //StepperMotor motor = StepperMotor(50);
  18. //StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);
  19. // 电流传感器
  20. // shunt resistor value
  21. // gain value
  22. // 引脚相位A、B(C可选)
  23. InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, _NC, A2);
  24. // 角度设定点变量
  25. float target_angle = 0;
  26. // instantiate the commander
  27. //Commander command = Commander(Serial);
  28. //void doTarget(char* cmd) { command.scalar(&target_angle, cmd); }
  29. void setup() {
  30.   // 初始化电流感应
  31.   current_sense.init();
  32.   // for SimpleFOCShield v2.01/v2.0.2
  33.   current_sense.gain_b *= -1;
  34.   // 初始化磁传感器硬件
  35.   sensor.init();
  36.   // 将电机连接到传感器
  37.   motor.linkSensor(&sensor);
  38.   // 驱动程序配置
  39.   // power supply voltage [V]
  40.   driver.voltage_power_supply = 24;
  41.   driver.init();
  42.   //连接电机和驱动器
  43.   motor.linkDriver(&driver);
  44.   // 选择FOC调制(可选)
  45.   motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
  46.   // 设置要使用的运动控制回路
  47.   motor.controller = MotionControlType::angle;
  48.   // 控制器配置
  49.   // default parameters in defaults.h
  50.   // 速度PI控制器参数
  51.   motor.PID_velocity.P = 0.2;
  52.   motor.PID_velocity.I = 2;
  53.   motor.PID_velocity.D = 0;
  54.   //设置给电机的最大电压
  55.   motor.voltage_limit = 1;
  56.   //速度低通滤波时间常数
  57.   //越低过滤越少
  58.   motor.LPF_velocity.Tf = 0.01;
  59.   // 角度P控制器
  60.   motor.P_angle.P = 5;
  61.   //位置控制的最大速度
  62.   motor.velocity_limit = 20;
  63.   // 使用串行监控
  64.   Serial.begin(115200);
  65.   // comment out if not needed
  66.   //motor.useMonitoring(Serial);
  67.   // 初始化电机
  68.   motor.init();
  69.   // 对齐传感器并启动FOC
  70.   motor.initFOC();
  71.   // 添加目标命令T
  72.   //command.add('T', doTarget, "target angle");
  73.   Serial.println(F("电机准备就绪!"));
  74.   Serial.println(F("使用串行终端设置目标角度:"));
  75.   Serial.println("电流感应就绪!");
  76.   _delay(1000);
  77. }
  78. void loop() {
  79.   // 主要FOC算法功能
  80.   // the faster you run this function the better
  81.   // Arduino UNO loop  ~1kHz
  82.   // Bluepill loop ~10kHz
  83.   motor.loopFOC();
  84.   // 运动控制功能
  85.   // 速度、位置或电压(在电机控制器中定义)
  86.   // this function can be run at much lower frequency than loopFOC() function
  87.   // You can also use motor.move() and set the motor.target in the code
  88.   motor.move(target_angle);
  89.   // function intended to be used with serial plotter to monitor motor variables
  90.   // significantly slowing the execution down!!!!
  91.   // motor.monitor();
  92.   // user communication
  93.   // command.run();
  94.   PhaseCurrent_s currents = current_sense.getPhaseCurrents();
  95.   float current_magnitude = current_sense.getDCCurrent();
  96.   Serial.print(currents.a * 1000); // milli Amps
  97.   Serial.print("\t");
  98.   Serial.print(currents.b * 1000); // milli Amps
  99.   Serial.print("\t");
  100.   Serial.print(currents.c * 1000); // milli Amps
  101.   Serial.print("\t");
  102.   Serial.println(current_magnitude * 1000); // milli Amps
  103.   _delay(1000);
  104. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-9 09:51:13

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple ...

九、测试开环位置控制

实验注意:12V先不要上电,开环控制电机会发热,上电时间过久容易烧坏。最好等到程序编译上传后再上电,上电尽快操作。开环控制的目的主要是建立对电机控制的初步认识,以及验证电机和驱动板功能是否正常,不要停留太久!


【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  项目程序之四:测试开环位置控制
  实验开源代码

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  4.   项目程序之四:测试开环位置控制
  5. */
  6. // Open loop motor control example
  7. #include <SimpleFOC.h>
  8. // BLDC motor & driver instance
  9. // BLDCMotor motor = BLDCMotor(pole pair number);
  10. BLDCMotor motor = BLDCMotor(7);
  11. // BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
  12. BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
  13. // Stepper motor & driver instance
  14. //StepperMotor motor = StepperMotor(50);
  15. //StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);
  16. //target variable
  17. float target_velocity = 0;
  18. // instantiate the commander
  19. Commander command = Commander(Serial);
  20. void doTarget(char* cmd) {
  21.   command.scalar(&target_velocity, cmd);
  22. }
  23. void doLimit(char* cmd) {
  24.   command.scalar(&motor.voltage_limit, cmd);
  25. }
  26. void setup() {
  27.   // driver config
  28.   // power supply voltage [V]
  29.   driver.voltage_power_supply = 12;
  30.   // limit the maximal dc voltage the driver can set
  31.   // as a protection measure for the low-resistance motors
  32.   // this value is fixed on startup
  33.   driver.voltage_limit = 6;
  34.   driver.init();
  35.   // link the motor and the driver
  36.   motor.linkDriver(&driver);
  37.   // limiting motor movements
  38.   // limit the voltage to be set to the motor
  39.   // start very low for high resistance motors
  40.   // current = voltage / resistance, so try to be well under 1Amp
  41.   motor.voltage_limit = 2;   // [V]
  42.   // open loop control config
  43.   motor.controller = MotionControlType::velocity_openloop;
  44.   // init motor hardware
  45.   motor.init();
  46.   // add target command T
  47.   command.add('T', doTarget, "target velocity");
  48.   command.add('L', doLimit, "voltage limit");
  49.   Serial.begin(115200);
  50.   Serial.println("电机准备就绪!");
  51.   Serial.println("请设置目标位置");
  52.   _delay(1000);
  53. }
  54. void loop() {
  55.   // open loop velocity movement
  56.   // using motor.voltage_limit and motor.velocity_limit
  57.   // to turn the motor "backwards", just set a negative target_velocity
  58.   motor.move(target_velocity);
  59.   // user communication
  60.   command.run();
  61.   _delay(1000);
  62. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 17:19:50

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图3
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 17:21:50

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图3
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 17:23:54

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图3
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 18:23:12

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

一、 概述
艾尔赛Arduino FOC无刷电机驱动板采用3个分立的高低边栅极驱动器和6NMOS管组成1BLDC驱动电路兼容国外开源项目Simple FOC Shield V2.0.4,可直接插入到Arduino NNO开发板作为一个Shiled来使用,并支持多种传感器接口,用户可以使用Arduino环境下的Simple FOC库来控制BLDC无刷电机平稳高精度运行
二、 功能特点   
1采用3IR2104栅极驱动器和6NMOS组成BLDC驱动部分,控制逻辑兼容官方原版Simple FOCL6234PD方案
2接口兼容Arduino UNOArduino MEGASTM32 Nucleo
3板载2INA240高精度电流传感器用于测量A B相电流
4用户可以通过0R电阻跳线的方式来配置GPIO控制管脚
5支持霍尔、磁传感器等多种编码器
6供电电压DC12-35V
7,板载电源指示灯。
三、 硬件介绍和说明
1,板子尺寸:67.8*53mm
   重量:26g

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 18:26:06

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

本帖最后由 驴友花雕 于 2024-7-3 05:03 编辑

2, 接口介绍

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1


1VCCGNDDC12-35V供电;
2A, B, C无刷电机接口;
3GPIO引出口,可直接插入到Arduino UNO等开发板
4IR2104供电跳线帽:因为IR2104最大只支持20V供电,故当VCC小于等于20V时此跳线帽插在左端,此时IR2104的电源电压等于VCC;当VCC20V时此跳线帽插在右端,此时IR2104的电源电压等于16V


【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

板子背面为GPIO控制/供电 选择跳线电阻,具体的跳线方法可参考电路原理图(一般保持默认即可)

电原理图

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图3

插入Arduino uno开发板

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图5

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图4


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 19:32:12

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

本帖最后由 驴友花雕 于 2024-7-2 20:09 编辑

四、Arduino开发环境搭建
1、安装Arduino IDE 1.8.9或者最新的版本;

2、点击菜单栏的 工具--管理库--开发板管理器,再搜索“Simple FOC”安装2.1.0或者更新版本(备注:安装最新版本可能导致后续的电流检测程序编译通不过);

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 20:10:28

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

更多资料:
Arduino简单磁场定向控制(FOC)项目
https://docs.simplefoc.com/

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 20:52:57

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

五、基本功能测试

1、硬件准备:Arduino UNO开发板、Arduino FOC驱动板、MKS YT2804无刷电机(DC12V@7极对@带AS5600磁编码器)、DC12V直流电源、USB方口线。

2、接线方法
● 无刷电机:接到驱动板的A B C三个口上
● AS5600编码器:5V和GND接驱动板的5V和GND,SCL和SDA分别接驱动板的SCL和SDA
● Arduino开发板USB口:通过方口USB线连接至电脑USB口
● 驱动板VCC GND供电口:接DC12V电源

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 21:15:10

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

六、开环速度测试
● 打开Arduino IDE,依次点击:文件--示例-- Simple FOC--motion_control --open_loop_motor_control --open_loop_velocity_example

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 21:35:35

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

● 根据所用电机修改参数:
BLDCMotor motor = BLDCMotor(11) 修改为 BLDCMotor motor = BLDCMotor(7)

motor.voltage_limit = 3 修改为 motor.voltage_limit = 1

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-2 21:43:42

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

本帖最后由 驴友花雕 于 2024-7-3 05:35 编辑

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  项目程序之一:开环速度测试
  开源参考程序
  1. /*
  2. 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  4.   项目程序之一:开环速度测试
  5. */
  6. // 开环电机控制示例
  7. #include <SimpleFOC.h>
  8. // BLDC 电机及驱动器实例
  9. // BLDCMotor motor = BLDCMotor(pole pair number);
  10. BLDCMotor motor = BLDCMotor(7);
  11. // BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
  12. BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
  13. // 步进电机及驱动器实例
  14. //StepperMotor motor = StepperMotor(50);
  15. //StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);
  16. //目标变量
  17. float target_velocity = 0;
  18. // 创建实例化对象
  19. Commander command = Commander(Serial);
  20. void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
  21. void setup() {
  22.   // 驱动配置
  23.   // 电源电压[V]
  24.   driver.voltage_power_supply = 12;
  25.   driver.init();
  26.   // 连接电机和驱动器
  27.   motor.linkDriver(&driver);
  28.   // 限制运动
  29.   motor.voltage_limit = 1;   // [V]
  30.   motor.velocity_limit = 5; // [弧度/秒] 约 50rpm
  31.   // 开环控制配置
  32.   motor.controller = MotionControlType::velocity_openloop;
  33.   // 初始化电机硬件
  34.   motor.init();
  35.   //添加目标命令 T
  36.   command.add('T', doTarget, "target velocity");
  37.   Serial.begin(115200);
  38.   Serial.println("电机就绪!");
  39.   Serial.println("设定目标速度 [rad/s]");
  40.   _delay(1000);
  41. }
  42. void loop() {
  43.   // 开环运动速度
  44.   // using motor.voltage_limit and motor.velocity_limit
  45.   motor.move(target_velocity);
  46.   // user communication 用户沟通
  47.   command.run();
  48. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 13:01:10

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

实验串口返回情况

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 14:08:38

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

打开“串口监视器”,等待串口输出 “电机就绪!” 信息后输入电机速度值(比如:T10),点击“发送”,电机会以设定的速度转动。比如再输入T30,电机转动速度会加快。

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 15:45:02

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

七、测试AS5600编码器

● 打开Arduino IDE,依次点击:文件--示例--Simple FOC --utils--sensor_test -- magnetic_sensors --magnetic_sensor_i2c_example

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 15:56:05

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
项目程序之二:测试AS5600编码器
实验开源代码

  1. /*
  2. 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FOC Shield V2.0.4(艾尔赛)
  4.   项目程序之二:测试AS5600编码器
  5. */
  6. #include <SimpleFOC.h>
  7. // MagneticSensorI2C(uint8_t _chip_address, float _cpr, uint8_t _angle_register_msb)
  8. //  chip_address  I2C chip address
  9. //  bit_resolution  resolution of the sensor
  10. //  angle_register_msb  angle read register msb
  11. //  bits_used_msb  number of used bits in msb register
  12. //
  13. // make sure to read the chip address and the chip angle register msb value from the datasheet
  14. // also in most cases you will need external pull-ups on SDA and SCL lines!!!!!
  15. //
  16. // For AS5058B
  17. // MagneticSensorI2C sensor = MagneticSensorI2C(0x40, 14, 0xFE, 8);
  18. // AS5600 配置示例
  19. MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
  20. void setup() {
  21.   // 监控端口
  22.   Serial.begin(115200);
  23.   // 配置 i2C
  24.   Wire.setClock(400000);
  25.   // 初始化磁传感器硬件
  26.   sensor.init();
  27.   Serial.println("传感器就绪!");
  28.   _delay(1000);
  29. }
  30. void loop() {
  31.   // iterative function updating the sensor internal variables
  32.   // it is usually called in motor.loopFOC()
  33.   // this function reads the sensor hardware and
  34.   // has to be called before getAngle nad getVelocity
  35.   sensor.update();
  36.   
  37.   // 将角度和角速度显示到终端
  38.   Serial.print(sensor.getAngle());
  39.   Serial.print("\t");
  40.   Serial.println(sensor.getVelocity());
  41.   _delay(1000);
  42. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 15:57:34

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

实验场景图

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 15:59:34

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

点击“上传”,打开串口监视器,可以监测电机的位置和转速

用手转动电机,可以发现电机位置与转速发生改变
关于位置:正转一圈约数值增加6.28(2π),反转一圈数值减少6.28(2π),如下图:

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图2

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-3 20:13:07

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple FO...

本帖最后由 驴友花雕 于 2024-7-3 20:14 编辑

实验记录视频(30秒)


{花雕动手做}Arduino FOC 无刷电机的开环速度测试


https://www.bilibili.com/video/BV1cH4y1A77x/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5


{花雕动手做}Arduino FOC 无刷电机的开环速度测试_哔哩哔哩_bilibili







回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2024-7-5 11:01:47

实验二百二十二:Arduino FOC无刷电机驱动板 兼容Simple ...

本帖最后由 驴友花雕 于 2024-7-5 11:05 编辑

实验串口返回情况
串口输出截图

【花雕学编程】Arduino动手做(222)---Simple FOC Shield V2.0.4图1

回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail