PolarRobotics / PolarRobotics/PR-ESPIDFCodebase

MotorControl

Open
#18 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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-TestingESP32PRCodebase/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.hDrive.cpp)
  • Encoder Pins (default to -1 for 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


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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.