Sections
You are here: Home Forum Bugs, Known Issues, & Requests Problem setting different speeds at the same time with stepper motors

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

Posted by Cleon Santos at April 21. 2008

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

Posted by Tim Broyles at April 22. 2008

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

Posted by Cleon Santos at April 23. 2008

Hi Tim,


Thank you for the tip, I will give it a try and post results.

Regards,
Cleon

Re: Problem setting different speeds at the same time with stepper motors

Posted by Cleon Santos at April 29. 2008

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

Posted by Cleon Santos at May 02. 2008
Hello, I thought that this was the place to get support for the MC, but until today none of my questions have any kind of answer from the makingthings team. Just buy it and if you have problems ... you are on your own? So this is just pure marketing? I'm sorry to say that MC looks a great product but without proper (or any) support there's no point in buying it (Especially when you buy more than one MC with a price of $109 USD each). I'm not asking miracles, just simple and quick answers. Anyway, I must say "thank you" to the other members who at least tried to help. Regards, Cleon

Re: Problem setting different speeds at the same time with stepper motors

Posted by Laurent Ricard at May 05. 2008
Hi, This is probably not related to your issue, but it seems there is a little glitch in the stepper support code (stepper.c). In Stepper_Stop, one can read: Free( s ); s = NULL; While in all rigor (mortis...) it should be Free( s ); Stepper->control[ index ] = NULL; My .0005 Euro... Laurent

Re: Problem setting different speeds at the same time with stepper motors

Posted by Cleon Santos at May 05. 2008
Laurent, Thank you for the tip, any help is always appreciated since these glitch's can make a difference. Tomorrow I will test my code with that correction, who knows if it helps my case. Regards, Cleon

Re: Problem setting different speeds at the same time with stepper motors

Posted by Cleon Santos at May 05. 2008

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

Re: Problem setting different speeds at the same time with stepper motors

Posted by Cleon Santos at May 05. 2008
Sorry about the the bad quote above. Here's the text again: 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
Powered by Ploneboard
Document Actions