Thanks for the reply!
I finally got the chance to work on the changes you mentioned.

Originally Posted by
luni
For a quick test I'd comment the 'mode == Mode::target &&' in the condition in line 132 to enable it for the rotation controller. You should also comment out line 135 since you don't want to stop the motor when it reached the target.
In setup you'd attach your callback (maybe start with just printing something in the callback to see if it works).
After making the changes, I tried it moving the motor using StepController and the following program.
Code:
#include <Arduino.h>
#include <TeensyStep.h>
#define STEP 2
#define DIR 3
#define ENABLE 4
#define ALARM 5
#define BRAKE 6
Stepper motor(2, 3);
// RotateControl controller;
StepControl stepController;
int positionArr[] = {800, 1200, 1600, 2000, 3000, 5000};
int arrayLength = 6;
int arrayCount = 0;
float speedFactor = 0.3;
int previous = 0;
void handleCommands()
{
if (Serial.available() > 0)
{
int cmd = Serial.read();
switch (cmd)
{
case '1':
if(!stepController.isRunning())
{
Serial.println("Starting Motor");
motor.setTargetAbs(positionArr[arrayCount]);
motor.setMaxSpeed(speedFactor * 3500);
stepController.moveAsync(motor);
}
break;
case '2':
stepController.stop();
Serial.println("Stopping motor");
break;
default:
break;
}
}
}
void positionCallback()
{
Serial.println("CALLBACK");
motor.setTargetAbs(positionArr[arrayCount]);
motor.setMaxSpeed(speedFactor * 3500);
arrayCount++;
speedFactor = speedFactor + 0.1;
if(arrayCount == arrayLength)
{
Serial.println("STOPPING");
stepController.stop();
}
}
void setup() {
motor.setMaxSpeed(3500);
motor.setAcceleration(3500);
motor.setStepPinPolarity(LOW);
motor.setInverseRotation(true);
stepController.setCallback(positionCallback);
pinMode(ENABLE, OUTPUT);
digitalWrite(ENABLE, HIGH);
pinMode(BRAKE, OUTPUT);
digitalWrite(BRAKE, LOW);
}
void loop() {
handleCommands();
int current = motor.getPosition();
if(current - previous == 1 || current - previous == -1)
{
Serial.print("Position: ");
Serial.println(current);
previous = current;
}
}
The motor stops even thought I commented the line you mentioned. I moved the motor using RotateControl and the callback function was called only when the controller.stop() was called.

Originally Posted by
luni
If you can explain what you want to achieve with your trajectories, I can probably tell you if TeensyStep is the right tool or if you would be better off using something else.
I am trying to create a manipulator arm, so accuracy is important, and the trajectory is provided by a motion planning package for ROS. So i need to execute the trajectory to move the motor from one pose to another.