PolarRobotics / PolarRobotics/PR-ESPIDFCodebase
MotorControl
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 9
- Forks
- 1
- Avg merge
- 14m
- Merged PRs (30d)
- 3
Description
MotorControl
Contains all functionality for controlling a PWM motor and reading an optional encoder for that motor. Also has functionality for controlling a commanded speed (PI loop).
Goal
Motor-specific class
Meaning that a motor is treated as an object and the encoder data of that motor, as well as ramping and commanding the motor’s speed, is all accomplished inside MotorControl.
- Pass in the motor type on instantiation
- BSN values are calculated inside the motor object
- Used for special motors as well
- To be used for the flywheel motors on the quarterback as well
Scope
- Generic motor class, to be used with ALL motors, special and drive
- Useful for closed-loop motors and actuators
- Anything that requires more than one motor is outside this scope
Milestones
Initial Implementation
- Need to test how Sabertooth responds to the PWM input
- Need to associate an RPM to a motor percent value
- Functions to convert % to RPM and RPM to % — needs to be public
- Move in working encoder code from
PR-Sandbox/Encoder-Code-Testing→ESP32PRCodebase/dev/motor-feedback - Class needs to store and do necessary logic related to MotorType
- Ramp to be refactored to work with RPM and take an acceleration value input, and moved to MotorControl, as the function is motor-dependent
PI Loop Implementation
- The PI loop will reside here
- Gains to be tuned and stored in a lookup table determined by the robot index in the array
- This can also just be dependent on the MotorType
Breakdown
Inputs
- MotorPins (from
PolarRobotics.h→Drive.cpp) - Encoder Pins (default to
-1for no encoder) - MotorType (from
RobotConfig) - Gear Ratio (from
RobotConfig) - Commanded Motor Power or Percent Power
- Override for BSN-selected motor power for cases with special motors
Functions
Private:
ramp()
Public:
commandMotorRPM(float pct, bool use_ramp)
Details
- Entire closed-loop system, motor-specific
- Goal is to command a motor to a given RPM and have the PI loop achieve that RPM
- Move control elements (encoder reading and motor-related code) to a specific MotorControl class
- Handles commands to the motor and encoder values from the wheel
Example Function Calls
M1.write(-1);
float speed = M1.getSpeed();
Links
- [Microcontroller I/O ADC Benchmarks – Arduino Forum](https://forum.arduino.cc/t/microcontroller-i-o-adc-benchmarks/315304/33)
- [ESP32 Interrupts Tutorial – Upesy](https://www.upesy.com/blogs/tutorials/what-are-interrupts-in-esp32-with-examples-for-arduino-code#:~:text=The%20use%20of%20interrupts%20on,any%20GPIO%20pin%20for%20interrupts.&text=It%20is%20recommended%20to%20add,that%20the%20function%20runs%20faster)
- [PID Loops: A Comprehensive Guide – Wevolver](https://www.wevolver.com/article/pid-loops-a-comprehensive-guide-to-understanding-and-implementation)
- [Introduction to PID Control Loops – Erdos Miller](https://info.erdosmiller.com/blog/introduction-to-pid-control-loops)
- [Introduction to PID Controllers (2nd Edition) – George Gillard](https://georgegillard.com/component/osdownloads/routedownload/robotics/introduction-to-pid-controllers-2nd-edition)
Comments
RD:
A simple implementation of PID for an inverse kinematic ball balancer project:
Ball-Balancer-V2/Ball_Balancing.ino at main · aaedmusa/Ball-Balancer-V2
GB:
Attach interrupt to A channel and have it digitally read B channel to determine direction. We are fairly confident that read time will not be a problem.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing motor and encoder code referenced in PR-Sandbox/Encoder-Code-Testing and ESP32PRCodebase/dev/motor-feedback, along with MotorPins in PolarRobotics.h, Drive.cpp, and MotorType in RobotConfig. The issue calls for a broad MotorControl design covering PWM, encoders, RPM conversion, ramping, and a PI loop; done means these milestones are implemented for generic and special motors and validated on the Sabertooth hardware.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot, robotics
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100