Octave-Arduino- Slow Velocity Stepper Motor

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave-Arduino- Slow Velocity Stepper Motor

Vicent
This post was updated on .
  Hi!
  I'm trying to control a robotic hand with stepper motors using arduino
with octave because I'm doing the angles calculations to get predefined
trajectories.

  The problem is the slow velocity I get  in the steppers (using Octave and
arduino toguether) because to get one complete turn  (200 steps ) it last
almost 11 seconds whereas only with arduino (without Octave) it goes really
fast but I prefer use Octave to be able to do the trajectory calculations.

   I'm using ubuntu 18.04 , arduino package 0.3.0 and Octave 4.2.2 in a
Desktop Intel® Core™2 CPU 6600 @ 2.40GHz × 2 and 4GB RAM
   I've used also  windows 10, arduino package 0.4.0 and Octave 5.1.0 in a
laptop 4GB RAM intel core i3 2GHz with more or less the same result.

The steppers are connected using the RAMPS 1.4 Board and the  pololu driver
A4988. The stepper motors are Longruner 17HS16-2004S

This is an extract of my test program.
Thanks in advance
Vicent


alfaStep = "d46"; # Firs Arm    step pin
alfaDir = "d48";  # Firs Arm    step direction
alfaEnable = "a8";

ar = arduino();

configurePin (ar, alfaStep, "DigitalOutput");
configurePin (ar, alfaDir, "DigitalOutput");
configurePin (ar, alfaEnable, "DigitalOutput");

writeDigitalPin (ar, alfaEnable, 0);   #Enable alfaMotor
                                                                            #Function to do a number of steps
function runMotor(ar, MotorStep, MotorDir, direction,  steps, time )
                                       
      writeDigitalPin (ar, MotorDir, direction);
   
      for x = 1:steps  
          writeDigitalPin (ar, MotorStep, 1);                 # do the steps
          pause(time);
          writeDigitalPin (ar, MotorStep, 0);
          pause(time);
      endfor
     
  endfunction

running = 1;
while (running == 1)
  answer = input('Select Movement  ',"s");
 
  switch answer;
    case "q"                                                   #    Alfa Motor Up;
                       #  Send  StepPin, DirectionPin, direction, steps and pause time
      runMotor (ar, alfaStep, alfaDir, 0, 200, 0.00001);    
   
    case "a"                                                   #   Alfa Motor Down;  

      runMotor (ar, alfaStep, alfaDir, 1, 200, 0.00001);
     
    otherwise
      running = 0;

  endswitch

 endwhile



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Octave-Arduino- Slow Velocity Stepper Motor

Ron.Simonson


On 9/5/19 10:23 AM, Vicent wrote:
> [External]
>
>    Hi!
>    I'm trying to control a robotic hand with stepper motors using arduino
> with octave because I'm doing the angles calculations to get predefined
> trajectories.
>
>    

I wonder if running something like grbl on the Arduino to control
the motion, and use Octave to calculate and write the G-code to
the Arduino might be useful.  Send the motion controls as blocks
of data rather than try to send individual movement commands.
Using a non "real time" OS to control motion is not going to result
in smooth operation.  Adding something like Octave on top of that
would exacerbate that problem even more I would expect.

Best of luck.  Talk to you later.  Ron.


Reply | Threaded
Open this post in threaded view
|

Re: Octave-Arduino- Slow Velocity Stepper Motor

Octave - General mailing list
In reply to this post by Vicent
On 9/5/19 1:23 PM, Vicent wrote:

>    The problem is the slow velocity I get  in the steppers (using Octave and
> arduino toguether) because to get one complete turn  (200 steps ) it last
> almost 11 seconds whereas only with arduino (without Octave) it goes really
> fast but I prefer use Octave to be able to do the trajectory calculations.
> ...
> function runMotor(ar, MotorStep, MotorDir, direction,  steps, time )
> ...
>            pause(time);
> ...
>    endfunction
> ...#
> Alfa Motor Down;
>        runMotor (ar, alfaStep, alfaDir, 1, 200, 0.00001);

You put far too much trust into pause()'s ability to execute short
delays. 10 microsecond pause is just not practical in the interpreted
environment: on my 3GHz Linux box I see a factor of 67 discrepancy:

tic; pause(.00001);toc
Elapsed time is 0.000674963 seconds.

Since that delayed delay happens in your step loop i'ts going to slow
things down significantly.



Reply | Threaded
Open this post in threaded view
|

Re: Octave-Arduino- Slow Velocity Stepper Motor

Vicent
Thanks Przemek Klosowski.
Yes, you are right.

I forgot to say before that without the pause instruction the result was
almost the same. I got 10 seconds for a complete turn.
 



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Octave-Arduino- Slow Velocity Stepper Motor

Vicent
This post was updated on .
In reply to this post by Ron.Simonson
Ron Simonson, that  would be the better solution. I'll try to do it.

Thank you very much.

Vicent



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Octave-Arduino- Slow Velocity Stepper Motor

Octave - General mailing list
In reply to this post by Vicent
On 9/5/19 2:38 PM, Vicent wrote:
> I forgot to say before that without the pause instruction the result was
> almost the same. I got 10 seconds for a complete turn.

Use the tic/toc technique to time writeDigitalPin()--you will probably
find that it's slower than you think.

It is well known than stepping pulse train in software is not a good
idea---you need speed AND regularity in the timing sequence, or else the
motor will run slowly and unreliably.

As the others have said, redesign your system so that Octave calculates
the high-level parameters like the total number of steps, and send it to
a hardware step generator or at least a real-timish software step
generator.



Reply | Threaded
Open this post in threaded view
|

Re: Octave-Arduino- Slow Velocity Stepper Motor

Vicent
Thanks again Przemek , I didn't know the tic/toc technique.
I see I have to redesign the system and try to use grbl or LinuxCNC , I'm
newbie in this and I need to collect more information.
Thanks for your help and  quick response.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html