Problem setting different speeds at the same time with stepper motors
Up to Bugs, Known Issues, & Requests
Problem setting different speeds at the same time with stepper motors
Hello,
I have a Make controller kit and I'm using 2 step motors to make my robot following a black/white line. Everything was tested with mchelper without any problems. Problem is when I in C I try to set each engine at different speeds. Example: Stepper 0 at 10 and Stepper 1 at 30. Here's an example:
#include "config.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
#define LEFT_ENGINE 0
#define RIGHT_ENGINE 1
#define MIN_SPEED 10
#define MAX_SPEED 30
#define STEP 1
void Run( ) {
int Left, Center, Right;
Usb_SetActive( 1 );
// Define robot name
System_SetName( "R23");
// Fix for initial negative stepping
Stepper_SetPosition( LEFT_ENGINE, 100000);
Stepper_SetPosition( RIGHT_ENGINE, 100000);
while ( true ) {
Right = AnalogIn_GetValue(0);
Center = AnalogIn_GetValue(1);
Left = AnalogIn_GetValue(2);
// FRONT 1 - 0 - 1
if ( Left > 1000 && Center < 10 && Right > 1000 ) {
Stepper_SetSpeed( LEFT_ENGINE, MAX_SPEED );
Stepper_Step( LEFT_ENGINE, STEP );
Stepper_SetSpeed( RIGHT_ENGINE, MAX_SPEED );
Stepper_Step( RIGHT_ENGINE, STEP );
// LEFT 0 - 1 - 1
// ***** Problem is here, in these next two if's where I want to set different speeds for each steeper *****
} else if ( Left < 10 && Center > 1000 && Right > 1000 ) {
Stepper_SetSpeed( LEFT_ENGINE, MIN_SPEED );
Stepper_Step( LEFT_ENGINE, STEP );
Stepper_SetSpeed( RIGHT_ENGINE, MAX_SPEED );
Stepper_Step( RIGHT_ENGINE, STEP );
// RIGHT 1 - 1 - 0
} else if ( Left > 1000 && Center > 1000 && Right < 10 ) {
AppLed_SetState( 0, 0 ); AppLed_SetState( 1, 1 ); AppLed_SetState( 2, 1 );
Stepper_SetSpeed( LEFT_ENGINE, MAX_SPEED );
Stepper_Step( LEFT_ENGINE, STEP );
Stepper_SetSpeed( RIGHT_ENGINE, MIN_SPEED );
Stepper_Step( RIGHT_ENGINE, STEP );
} else {
Stepper_SetActive( 0, 0 );
Stepper_SetActive( 1, 0 );
}
}
}
Also, is it possible to send OSC commands via C language? If so how? And should I use the Sleep(value) after each stepper instruction? So it can execute each stepper instruction before next one?
Thank you very much for your time.
Regards,
Cleon
Re: Problem setting different speeds at the same time with stepper motors
I am not running two steppers, just one. But one thing I found is that when I set a stepper inactive it does not remember what its settings were. (they reset to the default)
The way I inactiveate the stepper (which is important because it draws 2x the current while holding a position than it does while stepping) is to set the duty cycle to 0.
Give that a shot I think it will help.
Tim
Re: Problem setting different speeds at the same time with stepper motors
Re: Problem setting different speeds at the same time with stepper motors
Hello again,
It does not fix the problem. I can't set different speeds and/or different directions at the same time. Even when I try an infinite cycle doing this (using the same define values as above):while ( true ) {
Stepper_SetSpeed( LEFT_ENGINE, MIN_SPEED );
Stepper_Step( LEFT_ENGINE, STEP );
Stepper_SetSpeed( RIGHT_ENGINE, MAX_SPEED );
Stepper_Step( RIGHT_ENGINE, STEP );
}
Cleon
Re: Problem setting different speeds at the same time with stepper motors
Re: Problem setting different speeds at the same time with stepper motors
Re: Problem setting different speeds at the same time with stepper motors
Re: Problem setting different speeds at the same time with stepper motors
Previously Tim Broyles wrote:
><p>I am not running two steppers, just one. But one thing I found is that when I set a stepper inactive it does not remember what its settings were. (they reset to the default)<p>
><p>The way I inactiveate the stepper (which is important because it draws 2x the current while holding a position than it does while stepping) is to set the duty cycle to 0.<p>
><p><p>
><p>Give that a shot I think it will help.<p>
><p><p>
><p>Tim<p>
><blockquote> Tim, I also notice that when I use active 0 to "stop" them they lost everything, it's like a reset (indirectly). How did you find that it draws 2x the current? Did you check with a multimeter if it really draws 2x the current? I'm asking this because sometimes I will need to stop the robot in the middle of a ramp and I can not set duty to 0 but I was thinking in setting the duty to half the value to compensate!?!?. I will test it tomorrow and post results. Thank you. Regards, Cleon

