Stepper motors, run out of sync

Hi.

I’m trying to get stepper X To push a rack forward, then stepper Y to rev a gear one full rev, then X to retract rack. this must happen when a push button is pressed. I’ve not yet gotten to the button but already I’ve run into a problem.
The first part works fine, but as soon as the rack disengages, Y does another revolution.
Y is only supposed to turn while the rack is extended.
I’ll attach the code and some pics as well…

_2motor.ino (879 Bytes)

Pic of what the assembly looks like.

Please go read the forum rules about posing code & pics.

This is how you post code:

#define en 8
#define xdir 5
#define push 2
#define barrel 4

 int count_p = 0;
 int count_b = 0;
 boolean dir = LOW;
 
 void setup()
 
 {
   Serial.begin(9600);
 pinMode(en, OUTPUT);
 pinMode(xdir, OUTPUT);
 pinMode(push, OUTPUT);
 pinMode(barrel, OUTPUT);
 
 digitalWrite(en, LOW);
 }
 
 void loop()
 
 {
   count_b = 0;
   
   do
   {
   digitalWrite(push, HIGH);
   delay(1);
   digitalWrite(push, LOW);
   delay(1);
   count_p++;
   }while (count_p <= 100);
   
   delay(500);
   
   
   do   
   {digitalWrite(barrel, HIGH);
   delay(1);
   digitalWrite(barrel, LOW);
   delay(1);
   count_b++;
   }while (count_b <= 200);
 
  
  
  
  delay(500);
 
 dir = !dir;
 digitalWrite(xdir, dir);
 count_p = 0;
 
 do
   {
   digitalWrite(push, HIGH);
   delay(1);
   digitalWrite(push, LOW);
   delay(1);
   count_p++;
   }while (count_p <= 80);
   
   
   delay(500);
  
 }

This is how you post a pic:
fb55fe342c4daed7d240804efcf31c21214fcd1f.jpg

Thanks Paul.

Where do I find the rules?
I'm a hick from the rural areas of South Africa :confused:

Ok, Let’s try doing it right this time.

My code:

#define en 8
#define xdir 5
#define push 2
#define barrel 4

 int count_p = 0;
 int count_b = 0;
 boolean dir = LOW;
 
 void setup()
 
 {
   Serial.begin(9600);
 pinMode(en, OUTPUT);
 pinMode(xdir, OUTPUT);
 pinMode(push, OUTPUT);
 pinMode(barrel, OUTPUT);
 
 digitalWrite(en, LOW);
 }
 
 void loop()
 
 {
   count_b = 0;
   
   do
   {
   digitalWrite(push, HIGH);
   delay(1);
   digitalWrite(push, LOW);
   delay(1);
   count_p++;
   }while (count_p <= 100);
   
   delay(500);
   
   
   do   
   {digitalWrite(barrel, HIGH);
   delay(1);
   digitalWrite(barrel, LOW);
   delay(1);
   count_b++;
   }while (count_b <= 200);
 
  
  
  
  delay(500);
 
 dir = !dir;
 digitalWrite(xdir, dir);
 count_p = 0;
 
 do
   {
   digitalWrite(push, HIGH);
   delay(1);
   digitalWrite(push, LOW);
   delay(1);
   count_p++;
   }while (count_p <= 80);
   
   
   delay(500);
  
 }

Yeah, those rules are terribly hard to find. If only there was a sticky post at the top of each section on the forum!

Does this fix your problem?

void loop()
 
 {
   count_b = 0;
   count_p = 0;

Thanks Paul

I managed to find the rules :o

That still gives me the same effect.

Is there a way that I can post a short video to show you what's happening?
I just think you could better help if you can visualise what's happening..

See this Image Guide

The rest of the rules are at the top of every section of the Forum.

Your description is hard to relate to your code because you refer to X and Y in your description and to PUSH and BARREL in your code. And you also have XDIR in your code just to confuse yourself.

You should put som Serial.print() statements in your code so you can see the value of variables and maybe see that things as seen by the Arduino are not what you expect.

The code in loop() repeats over and over so maybe what you are experiencing is the whole sequence re-starting?

Or maybe you need a variable to record that something has happened so the code knows not to repeat it?

You have provided no information about the type of stepper motor, the type of driver or your motor power supply.

...R
Stepper Motor Basics
Simple Stepper Code

PS. If you upload a short video to YouTube you can add a link to it here.

ManV:
That still gives me the same effect.

Do you need to set the direction back to "extend" before the end of loop()?

Hi Robin.

Sure, I understand.

I'll try and be more clear in future.

Let me be as verbose as I can.

First of all, I'm using an Arduino Uno r3.
Mounted on that is a protoneer cnc shield v3,two stepper drivers, and an external 12v power supply connected.

In the code, stepper X refers to PUSH.
This is the stepper(NEMA17, 0.9deg/step) that pushes the rack outwards to disengage the barrel.
Y refers to the stepper(NEMA8, 1.8deg/step) that turns the BARREL assembly.
The gearing of the drive gear to the barrel gear is 1to6. Thus, one rev of the nema8 will mean that the barrel assembly will only turn 1/6 of a rev.

The projectiles fired(pneumatically) need to be pre-loaded into the 6 barrels, as this will be mounted on a drone. Because it is pneumatically driven, there needs to be a seal between the individual barrel and the exhaust.

So the barrel assembly is held in place by a spring to give a better seal. In order for the barrel assembly to turn, it needs to disengage first before rotating.
Thus the the PUSH rack.
At first, I used a relay triggered solenoid to push the barrel ass forward, but it wasn't strong enough.

I'm sure this gives you a pretty good idea of what I'm about.
I'll make a small video on Youtube and upload.

Okay, I've posted a short video to Youtube to show you guys what I need to do.
This project is still in its infancy, so I hope you guys can lend me help as we go along...
Youtube link : Stepper problem - YouTube

ManV:
Youtube link : Stepper problem - YouTube

Hey! You only read the rules a few minute ago and you already forgot them?

Links should look like this!

I thought you were going to show us what happens when your code runs?

Jeez Paul, sorry man :confused:

I'm really a pleb, figuring this sh*t out minute to minute.
I should maybe take a few minutes, have a coupla whiskeys and then start fresh.
Been struggling with this project for about three weeks now, maybe I'm a bit frustrated and impatient.
Gotta learn how to upload to Youtube and all!

ManV:
Stepper Problems 2 - YouTube

Maybe these things explain some of what is happening:

In the code for extending the rack:

   }while (count_p <= 100);

but then for retracting it:

   }while (count_p <= 80);

Why 100 steps in one direction and only 80 in the other?

Also what I said in my earlier post about changing the direction back again after the rack is retracted.

ManV:
The projectiles fired(pneumatically) need to be pre-loaded into the 6 barrels,

Sorry, but I don't help with guns, even toy guns.

...R

@Paul

I fixed that bug.
Still gives me the same thing.

@Robin

Robin,

The purpose of this 'gun' is to make it cheaper, and more effective, to dart wild animals to either run diagnostics or to administer needed medicine to said animals, should the diagnostic already have been run.

There are, in our area, also a shortage of 'intelligence' about plant, soil and crop conditions.

This 'gun', in my mind, is only the first step of a vast range of applications possible.

For example, darting (for diagnostic purposes) currently cost the average game-breeder more or less $450/hour, excluding ferrying costs.
If we could cut those costs by 1/3, it would mean that overall cost of diagnosis is cut by 6-9%.

Anyway, I digress.

Please help?

When you fix something, post your new code - hard to help otherwise

What kind of drone are you going to have carry this thing? Looks like a model A10 would be appropriate :wink:

ManV:
I fixed that bug.
Still gives me the same thing.

So... you didn't fix it. Post the updated code.

ManV:
...game-breeder...

This device is to tranquillise or medicate animals that will ultimately be killed either to eat or to provide some "entertainment" for morons with rifles? Or will the device itself be used to dispatch them?

I’ve only fixed the discrepancy in the steps of the push motor in the code.
Been struggling since early morning to figure out where I’m going wrong.
I’ve also moved the count_b = 0 to after the push motor engages, but still no luck.
It would seem to me as if count_b resets to zero when the loop starts again, causing the motor to step.
Should I maybe change something in the void setup()?

@wildbill

I’m looking at the DJI Matrice 600 with the Ronin gimbal to carry the payload.
I’ll still shop around a bit before I buy the drone. Want to get the proof of concept, uh, proven before I spend $10k on the drone.

@Paul

Regarding the re-engage of the push, I want the loop eventually to only run once when a button is pressed or a trigger is sent from the transmitter.
I know a lot of people have moral issues with the game breeding industry, but in reality it has pushed up population numbers of most species. We could go into a long debate about the whole thing, but I don’t think this is the place for it.
If you are unwilling to help because of your views on the application of the project, I would fully understand.

#define en 8
#define xdir 5
#define push 2
#define barrel 4

 int count_p = 0;
 int count_b = 0;
 boolean dir = LOW;
 
 void setup()
 
 {
   Serial.begin(9600);
 pinMode(en, OUTPUT);
 pinMode(xdir, OUTPUT);
 pinMode(push, OUTPUT);
 pinMode(barrel, OUTPUT);
 
 digitalWrite(en, LOW);
 }
 
 void loop()
 
 {
   
      do
   {
   digitalWrite(push, HIGH);
   delay(1);
   digitalWrite(push, LOW);
   delay(1);
   count_p++;
   }while (count_p <= 80);
   
   delay(500);
   
   count_b = 0;
   
   do   
   {digitalWrite(barrel, HIGH);
   delay(1);
   digitalWrite(barrel, LOW);
   delay(1);
   count_b++;
   }while (count_b <= 200);
 
  
  
  
  delay(500);
 
 dir = !dir;
 digitalWrite(xdir, dir);
 count_p = 0;
 
 do
   {
   digitalWrite(push, HIGH);
   delay(1);
   digitalWrite(push, LOW);
   delay(1);
   count_p++;
   }while (count_p <= 80);
   
   
   delay(500);
  
 }

I suspect game breeding pushes up the populations of the game animals themselves out of proportion to the natural level. That's how farming animals started. But what I find offensive is that some supposedly intelligent humans get pleasure out of killing animals, like we are still in the 18th century and unaware of the impact we have on the natural world. If it were up to me, I might allow hunting in a known sustainable way. Hunters would go barefoot and naked armed only will poison arrows or spears, with no backup. So having let off steam I will bow out of this thread with apologies.

But I will point out that I have suggested twice now what I think is still missing from your sketch, but you have ignored it, presumably because you did not understand, rather than asking what I meant.