I am desperately trying to get the DRV 8302 Driver, an Arduino Uno, an as5600 magnetic encoder, and my Propdrive V2 28-36 1000Kv to function. I am trying to make a robot dog, but before I continue with the design I need to verify this motors capability before I spend more time and money on making the rest of the dog. I have looked at various examples and other peoples code, and here is what I have found to work (not give me errors and provide an output)
#include <SimpleFOC.h>
// DRV8302 pins connections
// don't forget to connect the common ground pin
#define INH_A 9
#define INH_B 10
#define INH_C 11
#define EN_GATE 8
#define M_PWM 6
#define M_OC 5
#define OC_ADJ 7
// motor instance
BLDCMotor motor = BLDCMotor(6);
// driver instance
BLDCDriver3PWM driver = BLDCDriver3PWM(INH_A, INH_B, INH_C, EN_GATE);
// Changed encoder to magnetic encoder
MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);
void setup() {
// initialize magnetic sensor instead of regular encoder
sensor.init();
motor.linkSensor(&sensor);
// DRV8302 specific code
// M_OC - enable over-current protection
pinMode(M_OC,OUTPUT);
digitalWrite(M_OC,LOW);
// M_PWM - enable 3pwm mode
pinMode(M_PWM,OUTPUT);
digitalWrite(M_PWM,HIGH);
// OD_ADJ - set the maximum over-current limit possible
// Better option would be to use voltage divisor to set exact value
pinMode(OC_ADJ,OUTPUT);
digitalWrite(OC_ADJ,HIGH);
// configure driver
driver.voltage_power_supply = 10; //Using exernal power supply set on 10 volt with current limit set to 1 amps.
driver.init();
motor.linkDriver(&driver);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set control loop type to be used
//motor.controller = MotionControlType::voltage;
motor.torque_controller = TorqueControlType::voltage;
// set motion control loop to be used
motor.controller = MotionControlType::torque;
motor.useMonitoring(Serial);
// controller configuration based on the control type
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle loop controller
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 50;
// default voltage_power_supply
motor.voltage_limit = 1; //lowered the motor voltage due to the low internal resistance of the motor
// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
_delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outer loop target
// velocity, position or voltage
// if target not set in parameter uses motor.target variable
motor.move(1);
motor.monitor();
// user communication
// motor.command(serialReceiveUserCommand());
}
// utility function enabling serial communication the user
String serialReceiveUserCommand() {
// a string to hold incoming data
static String received_chars;
String command = "";
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the string buffer:
received_chars += inChar;
// end of user input
if (inChar == '\n') {
// execute the user command
command = received_chars;
// reset the command buffer
received_chars = "";
}}}
// return command;
It provides me with this as the output in the serial monitor:
MOT: Monitor enabled!
MOT: Iniensor.
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: fail - estimated pp: 15.46
MOT: Zero elec. angle: 2.73
MOT: No current sense.
MOT: Ready.
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
1.0000 1.0000 0.0000 -1.2410
When I rotate my motor the rightmost column seems to be reading the position data while the second from the right seems to be rotational speed.
My apologies for how bad I am at this. I am adept at MATLAB, but never learned C and its really coming to bite me right now. Does anybody know what to type into the serial monitor to command the program to rotate a certain amount or anything? I am unsure if the code is not working, or I just simply don’t know the control commands to input. Most likely both.