This class is to control a single motor. In robots with multi-DOF appendages, the AbstractMotor class and its derived classes (MinitaurLeg, SagittalPair, etc.) are useful. If you need to use MinitaurLeg, be sure to look at its help page.
Single motor
Basic control of a single motor:
- Call initialization function, like BlCon34::init() or DxlMotor::init()
- Call Motor::enable()
- Call Motor::setOpenLoop() with an argument between -1 and 1 to spin freely
- Call Motor::setGain() and Motor::setPosition() to command a position
- Call Motor::getPosition(), Motor::getVelocity() to get back data
- To get back proprioceptive torque estimates, call Motor::setTorqueEstParams() during initialization, and Motor::getTorque()
- Motor::update() must be called frequently, preferably through a timer interrupt (attachTimerInterrupt()) for BlCon34, or just as often as possible for DxlMotor
Example: single motor test
#include <Motor.h>
const int NMOT = 10;
const uint8_t outPin[] = {PE9, PE11, PE13, PE14, PA0, PD4, PD7, PD6, PB4, PB5};
const uint8_t inPin[] = {PD12, PD13, PD14, PD15, PC6, PC7, PC8, PC9, PE2, PE3};
const int CONTROL_RATE = 1000;
void controlLoop() {
for (int i=0; i<NMOT; ++i)
M[i].update();
}
void setup() {
Serial1.begin(115200);
for (int i=0; i<NMOT; ++i) {
M[i].
init(outPin[i], inPin[i], 0, 1);
}
}
void loop() {
}
Setting motor zero (independent of physical setup)
- Rotate the output shaft of the motor (or gearbox) to the desired zero location.
- Take the output of Motor::getRawPosition() (between 0 and 2 PI), and use that as the
zero
argument for the initialization function (BlCon34::init(), DxlMotor::init(), etc). The direction
and gearRatio
do not have any effect on the zeroing routine.
- For robot startup, the motor's output shaft must be within (-PI, PI)/gearRatio of the calibrated zero position. This means that in direct drive, the motor can be at an arbitrary position, but when using a gearbox the startup angle is decreased since there are no absolute enocders.
- If the motor driver setup takes some time (i.e. Motor::getRawPosition() returns garbage during init), then make sure to call Motor::resetOffset() after there is non-garbage data. This should not be an issue in PWM controlled motor controllers.
- For any gearbox with an integer ratio, the leg can recirculate and still work correctly. However, for gearboxes with non-integer ratios, the motor/gearbox assembly should NOT be allowed to recirculate ever because one full rotation of the output shaft results in a different Motor::getRawPosition() value.
Copyright (C) Ghost Robotics - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential Written by Avik De avik@.nosp@m.ghos.nosp@m.trobo.nosp@m.tics.nosp@m..io