Skip to content
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

feat(motor): using open_loop_velocity example #6

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

hcd-bdltd
Copy link
Owner

@hcd-bdltd hcd-bdltd commented Feb 8, 2024

Summary by CodeRabbit

  • Refactor
    • Transitioned from hall sensor-based control to open-loop motor control for BLDC motors, including setup and configuration adjustments.

@hcd-bdltd hcd-bdltd self-assigned this Feb 8, 2024
Copy link

coderabbitai bot commented Feb 8, 2024

Walkthrough

The recent code overhaul transitions from utilizing a hall sensor for motor control to implementing an open-loop control system for a BLDC motor. This shift entails removing the hall sensor configurations and interrupt routines, and instead, focusing on setting up the BLDC motor and its driver, establishing voltage and current limits, and initializing open-loop control.

Changes

Files Changed Summary of Changes
src/main.cpp Transitioned from hall sensor to open-loop motor control, including setup and initialization changes for BLDC motor and driver, and configuration of voltage and current limits.

🐰✨
To spin without a sense, we dare,
Open-loop whispers through the air.
No halls to guide, yet onward we stride,
With voltage and currents as our guide.
🌪️🔌

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 755329b and 071daa8.
Files selected for processing (1)
  • src/main.cpp (3 hunks)
Additional comments: 3
src/main.cpp (3)
  • 6-6: Ensure the pin definitions for A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, and A_PHASE_WL are defined elsewhere in the code or documentation, as they are critical for the motor driver initialization but not visible in the provided snippet.
  • 1-12: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [33-33]

Setting driver.voltage_limit after driver.init() might not have the intended effect if voltage_limit is only read during init(). Verify that this limit is correctly applied post-initialization or consider setting it before calling init().

  • 45-45: The addition of commands for setting target velocity and voltage limit is a good practice for dynamic control. However, ensure that input validation is performed within doTarget and doLimit functions to prevent setting values that could potentially damage the motor or the driver.

#include <SimpleFOC.h>

#define POLE_PAIRS 7

// Motor instance
// BLDC motor & driver instance
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instantiation of BLDCMotor and BLDCDriver6PWM directly in the global scope can lead to issues with initialization order, especially when dealing with hardware components. Consider moving these into the setup() function or ensuring their initialization is safe at the point of construction.

Comment on lines +1 to 12
// Open loop motor control example
#include <SimpleFOC.h>

#define POLE_PAIRS 7

// Motor instance
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(POLE_PAIRS);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);

// Hall sensor instance
// HallSensor(int hallA, int hallB , int hallC, int pp)
// - hallA, hallB, hallC - HallSensor A, B and C pins
// - pp - pole pairs
HallSensor sensor = HallSensor(A_HALL1, A_HALL2, A_HALL3, POLE_PAIRS);

// Interrupt routine initialisation
// channel A, B and C callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}

//target variable
float target_velocity = 0;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [25-25]

The delay of 2000 milliseconds in setup() might not be necessary or could be reduced, depending on the hardware initialization requirements. Evaluate if this delay can be shortened to speed up the startup process.


📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [55-55]

In the loop() function, there's an implicit assumption that target_velocity will be updated through the command interface. Ensure there's error handling or default behavior in case target_velocity is not set or receives invalid input.

@@ -62,13 +35,14 @@ void setup() {
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor.voltage_limit = 3; // [V]
motor.velocity_limit = 10; // [rad/s]

// open loop control config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about starting very low for high resistance motors and trying to be well under 1Amp is useful, but ensure there's a mechanism or recommendation for users to adjust motor.voltage_limit based on their specific motor's resistance. This could be in the form of documentation or a calculation example in the comments.

Comment on lines 43 to +45
motor.init();
// use monitoring with serial
motor.useMonitoring(Serial);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using motor.useMonitoring(Serial) enables monitoring over serial, which is great for debugging but consider the performance implications in a production environment. If the serial output is not needed in production, it might be beneficial to conditionally enable this feature.

@hcd-bdltd hcd-bdltd merged commit 6a68104 into main Feb 8, 2024
1 check passed
@hcd-bdltd hcd-bdltd deleted the open_loop_velocity_example branch February 8, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant