The code here controls the arm, based on input from an Xbox controller. The arm can swivel clockwise and counter-clockwise, lift up and down, and extend in and out. The gripper can be separately lifted up and down, rotated clockwise and counter-clockwise and pinch open and closed. The following image should illustrate that.
The arm has two modes: precision and IK. In precision mode, you move the joints individually by small increments. In IK mode, you control a reticle that determines the position of the gripper in 3D space. The system provides the translations between 3D coordinates and joint angles.
The arm uses TMC 5160 stepper motors, which have a lot of features but are complex and hard to use without adding bloat to a .ino
sketch. This library serves to simplify all the aspects of oeprating a TMC 5160 stepper motor with the StepperMotor
class. It's implementation builds on TMCStepper
library, which it uses as a backend.
Read the full documentation for details, but here are a few basics:
Declare your motor as a variable and initialize in setup
:
StepperMotor myMotor = StepperMotor(chipSelectPin, enablePin, rmsCurrent, minBound, maxBound, gearboxRatio);
void setup() {
myMotor.setup();
myMotor.calibrate();
}
The motor takes a while to move to its destination, and may stall along the way. Add some boilerplate to your loop
to handle these cases:
void loop() {
myMotor.fixPotentialStall(); // check and act on stalls
if (!myMotor.isFinished()) return; // still en-route
// Now you can safely move the motor
}
You have three options for moving the motor:
- Move by a given number of steps (debug):
myMotor.debugMoveSteps(50); // move 50 steps as a test
- Move by a given number of radians:
myMotor.moveBy(PI); // move a half rotation
- Move to a given rotation:
myMotor.moveTo(0); // back to the home position