Peter Lingaas
New member
Hi! I am building a library for running my robot arm. I have tried out all the code earlier and it works fine,
but now that I am using it via my library, micros() and elapsedMicros pauses the program. It runs for 5000-30000 microseconds
and then it pauses until its around 7 million microseconds and runs normally. This is the function that is using the code:
Everything runs properly when I dont use my RobotArm library, but when I use it elapsedMicros and micros() just pauses?
I have been messing around for 5 hours trying to figure it out, but I can't seem to find the issue.
This is how the code looks when its outside the library and runs just fine:
but now that I am using it via my library, micros() and elapsedMicros pauses the program. It runs for 5000-30000 microseconds
and then it pauses until its around 7 million microseconds and runs normally. This is the function that is using the code:
Code:
void RobotArm::goToWithTime(float x, float y, float z, float rx, float ry, float rz, float move_time)
{
Serial.println("STARTING MOVE");
Angles angles = IK(x, y, z);
if (!angles.legal || z < 50) {
Serial.println("ERROR: POSITION IS OUTSIDE OF WORKSPACE");
return;
}
int j1Steps = angles.theta1 * 88.88888889;
int j2Steps = angles.theta2 * 55.55555567;
int j3Steps = angles.theta3 * 55.55555567;
actuators[0].moveTo(j1Steps, move_time, acc_time_percentage, dec_time_percentage);
actuators[1].moveTo(j2Steps, move_time, acc_time_percentage, dec_time_percentage);
actuators[2].moveTo(j3Steps, move_time, acc_time_percentage, dec_time_percentage);
run();
}
void RobotArm::run()
{
bool a, b, c = false;
bool finished = false;
[B]elapsedMicros time_elapsed;
while (!finished)
{
a = actuators[0].run(time_elapsed);
b = actuators[1].run(time_elapsed);
c = actuators[2].run(time_elapsed);
finished = a && b && c;
}[/B]
Serial.println("New position reached");
}
Everything runs properly when I dont use my RobotArm library, but when I use it elapsedMicros and micros() just pauses?
I have been messing around for 5 hours trying to figure it out, but I can't seem to find the issue.
This is how the code looks when its outside the library and runs just fine:
Code:
void goTo(float x, float y, float z, float T, float t_in, float t_out) {
Angles angles = IK(x, y, z);
if (!angles.legal || z < 50) {
Serial.println("ERROR: POSITION IS OUTSIDE OF WORKSPACE");
return;
}
int j1Steps = angles.theta1 * 88.88888889;
int j2Steps = angles.theta2 * 55.55555567;
int j3Steps = angles.theta3 * 55.55555567;
Serial.println(j1Steps);
Serial.println(j2Steps);
Serial.println(j3Steps);
stepper1.moveTo(j1Steps, T, t_in, t_out);
stepper2.moveTo(j2Steps, T, t_in, t_out);
stepper3.moveTo(j3Steps, T, t_in, t_out);
bool a, b, c = false;
bool finished = a && b && c;
[B]elapsedMicros time_elapsed;
while (!finished) {
a = stepper1.run(time_elapsed);
b = stepper2.run(time_elapsed);
c = stepper3.run(time_elapsed);
finished = a && b && c;
}
Serial.println("FINISHED");[/B]
}
Last edited: