-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added: radians cmd #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,16 @@ void doA(){ hall_sensor.handleA(); } | |
void doB(){ hall_sensor.handleB(); } | ||
void doC(){ hall_sensor.handleC(); } | ||
|
||
// monitor delay | ||
#define MONITOR_DELAY_MS (20) | ||
unsigned long monitor_delay = 0; | ||
// angle set point variable | ||
float target = 0.0f; | ||
// instantiate the commander | ||
Commander commander = Commander(Serial); | ||
void doMotor(char* cmd) { commander.motor(&motor, cmd); } | ||
void doTarget(char* cmd) { | ||
void doRadians(char* cmd) { commander.scalar(&target, cmd); }; | ||
void doDegrees(char* cmd) { | ||
float angle_degrees; | ||
commander.scalar(&angle_degrees, cmd); | ||
target = angle_degrees * (PI / 180.0); | ||
|
@@ -51,7 +55,8 @@ void setup() { | |
// initialize the driver | ||
driver.voltage_power_supply = 24.0f; | ||
rc = driver.init(); | ||
checkRC(rc); SIMPLEFOC_DEBUG("Driver ready."); | ||
checkRC(rc); | ||
SIMPLEFOC_DEBUG("Driver ready."); | ||
// link the current sensor and the driver | ||
current_sensor.linkDriver(&driver); | ||
// link the motor and the driver | ||
|
@@ -60,7 +65,8 @@ void setup() { | |
// initialize the current sensor | ||
current_sensor.skip_align = true; | ||
rc = current_sensor.init(); | ||
checkRC(rc); SIMPLEFOC_DEBUG("Current sensor ready."); | ||
checkRC(rc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment on It would be helpful to include comments explaining the expected return codes from |
||
SIMPLEFOC_DEBUG("Current sensor ready."); | ||
// link the current sensor to the motor | ||
motor.linkCurrentSense(¤t_sensor); | ||
|
||
|
@@ -84,13 +90,13 @@ void setup() { | |
motor.P_angle.P = 20.0f; | ||
|
||
// motor limits | ||
motor.voltage_limit = 12.0f; | ||
motor.velocity_limit = 4.0f; | ||
motor.current_limit = 2.0f; | ||
motor.voltage_limit = 24.0f; | ||
motor.velocity_limit = 200.0f; | ||
motor.current_limit = 1.0f; | ||
|
||
// motion and monitoring settings | ||
motor.motion_downsample = 0; | ||
motor.monitor_downsample = 10000; | ||
motor.monitor_downsample = 1; | ||
|
||
// use monitoring with serial | ||
motor.monitor_separator = '\t'; | ||
|
@@ -102,16 +108,19 @@ void setup() { | |
motor.init(); | ||
// align sensor and start FOC | ||
rc = motor.initFOC(); | ||
checkRC(rc); SIMPLEFOC_DEBUG("Motor ready."); | ||
checkRC(rc); | ||
SIMPLEFOC_DEBUG("Motor ready."); | ||
|
||
// initialize serial communication | ||
commander.verbose = VerboseMode::user_friendly; | ||
commander.add('M',doMotor,"motor"); | ||
commander.add('T', doTarget, "target [deg]"); | ||
commander.add('R', doRadians, "target [rad]"); | ||
commander.add('D', doDegrees, "target [deg]"); | ||
|
||
SIMPLEFOC_DEBUG("Setup ready."); | ||
SIMPLEFOC_DEBUG("Set the target angle using serial terminal:"); | ||
_delay(1000); | ||
monitor_delay = millis(); | ||
} | ||
|
||
void loop() { | ||
|
@@ -127,9 +136,12 @@ void loop() { | |
// You can also use motor.move() and set the motor.target in the code | ||
motor.move(target); | ||
|
||
// function intended to be used with serial plotter to monitor motor variables | ||
// significantly slowing the execution down!!!! | ||
motor.monitor(); | ||
if (millis() - monitor_delay > MONITOR_DELAY_MS) { | ||
monitor_delay = millis(); | ||
// function intended to be used with serial plotter to monitor motor variables | ||
// significantly slowing the execution down!!!! | ||
motor.monitor(); | ||
} | ||
|
||
// user communication | ||
commander.run(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to
checkRC(rc)
after initializing the driver is a good practice for error handling. It ensures that any issues with the driver initialization are caught early. However, it would be beneficial to add comments explaining the expected range of return codes fromdriver.init()
and what conditions might lead to a failure, for better maintainability and clarity for future developers.Consider adding comments detailing the expected return codes from
driver.init()
and the conditions that might lead to initialization failure.