Thanks: 0
Needs Pictures: 0
Picture(s) thanks: 0
Results 136 to 150 of 163
Thread: Handling limit switches?
-
31st March 2015, 06:02 PM #136Senior Member
- Join Date
- Nov 2008
- Location
- somewhere
- Posts
- 152
You can muck with the speed now. I found the stepper was erratic if I sped it up too much, but its current value is based on me halving it and getting a pretty good result. I'm planning on your speed control pot giving you a range from quite slow up to the speed that its running at the moment. If its not fast enough you probably need to play with it to see how far you can crank it up and still get smooth movement. with my stepper I was dropping steps and getting erratic behaviour at 500.
The line:
#define MAX_SPEED 250 is the one you want to muck with.
Max shots was set at 2, to give you two changes to get a decent shot. You might be better off keeping the MAX_IDLE at 500 (or less), and adding an additional short delay at the end of the TrigCamera function.
At the moment the only reason the cnt increment and loops is really in there is to give enough of a delay that the debug information coming back to the serial monitor isn't a continual stream of spam. I've used it for convenience at this point, but I'm planning on yanking most of the stuff associated with it.
-
31st March 2015 06:02 PM # ADSGoogle Adsense Advertisement
- Join Date
- Always
- Location
- Advertising world
- Posts
- Many
-
31st March 2015, 08:03 PM #137Product designer retired
- Join Date
- Nov 2006
- Location
- Heidelberg, Victoria
- Age
- 79
- Posts
- 2,251
Camera slider update
Hi foob,
As mentioned earlier, turning the speed control pot has no effect, was this feature re implemented in the latest sketch?
Ken
-
31st March 2015, 09:14 PM #138SENIOR MEMBER
- Join Date
- Jun 2010
- Location
- Canberra
- Posts
- 769
Nope, but it's simple to add.
The complication with speed and steppers is that the attainable speed depends on a heap of variables, which change depending on the specific setup. So there's the actual stepper motor, there's the diameter of the gear/pulley you put on the thing, there's the mass of whatever you're trying to move, there's the friction of the bearing system it's riding on, and there's the voltage you're driving the stepper with.
With steppers, the top speed you want to step with any specific load is dependant on voltage, so if you find you're stalling/skipping steps, you can typically just increase the voltage to solve the problem, limited by how much the steppers heat up, and how much voltage the stepper control board can handle.
-
31st March 2015, 09:29 PM #139Product designer retired
- Join Date
- Nov 2006
- Location
- Heidelberg, Victoria
- Age
- 79
- Posts
- 2,251
Camera slider update
Hi Rus,
I appreciate the info on steppers. I'm using a nema17 motor 200 steps 0.3A per phase and running it from a 12V wall plug supply. In the field, the wall plug will be swapped out for a good quality battery. The toothed belt pulley is around 25mm dia.
I doubt there will be much resistance in the rail/carriage setup, all 4 wheels are ball bearing.
You say adding speed control is easy, and right you are, and it was working to some degree in earlier sketches, now not.
I've read through foobs latest sketch, and just can't identify which piece of code reads the speed pot. Maybe I need bigger glasses.
Ken
edit. Looked back through some of foobs earlier sketches, and found the code for reading the speed pot. Tried copying those few lines of code and pasting them into the latest sketch, and it would not compile.
So much for my measly knowledge!
-
1st April 2015, 08:34 AM #140Senior Member
- Join Date
- Nov 2008
- Location
- somewhere
- Posts
- 152
Hi Ken,
The speed is currently set by one of the defines up near the top of the code, not by the pot.
Look for the line
#define MAX_SPEED 250
and change the 250 to something higher. You can also increase the acceleration rate. You'll need to do some experimenting with your set up to figure out what MAX_SPEED is your actual maximum for smooth movement. In older versions of the code this use to be 500, but I could not get smooth movement on my stepper with that. your mileage may vary. Once I add the code for the pot back in it will use that MAX_SPEED setting as your "flat out" setting on your pot.
try increasing it by 100 or so until you get unstable/unreliable movement, then back it off until you get it working.
-
7th April 2015, 08:25 PM #141Product designer retired
- Join Date
- Nov 2006
- Location
- Heidelberg, Victoria
- Age
- 79
- Posts
- 2,251
Camera slider update
Hi foobillious,
No doubt your time is at a premium, and I'm grateful for what you have achieved so far, but is there any chance you could finish this project off?
Ken
edit: foob, I don't think the limit switch function works properly. If I depress the limit switch and keep it depressed, the motor will stop as it should, however, pressing the opposite push button does not move the motor.
The motor should move off the limit switch in the opposite direction.
-
9th April 2015, 07:24 PM #142Senior Member
- Join Date
- Nov 2008
- Location
- somewhere
- Posts
- 152
Hi Ken,
Sorry about the holdup. I was away from all things electronic over easter and I've since put my Uno to work as a test platform for another project. I've got an Arduino Pro mini comining to take over that job, which will hopefully arrive tomorrow. Even if that doesn't happen I'll have a go at finishing on saturday or sunday.
I'm pretty sure the limit switch issue is caused by CheckInputs determining movement is allowed, and then that gets overridden (actually ignored) by CheckStopEvent().
look around line 120 for:
if (CheckStopEvent())
and change it to
if (dir==0 && CheckStopEvent())
the limit switches should work. Its kind of dodgy (will fix properly later), because you'll get a step if you hold down the stop button and press one of the direction buttons, but I think it'll work.
-
10th April 2015, 08:47 PM #143Product designer retired
- Join Date
- Nov 2006
- Location
- Heidelberg, Victoria
- Age
- 79
- Posts
- 2,251
Camera slider update
Hi foobillious, thanks for the update.
Look forward to your next effort.
RustyArc,
Are you keeping up with proceedings?
Ken
-
10th April 2015, 09:25 PM #144SENIOR MEMBER
- Join Date
- Jun 2010
- Location
- Canberra
- Posts
- 769
-
11th April 2015, 10:23 AM #145SENIOR MEMBER
- Join Date
- Jun 2010
- Location
- Canberra
- Posts
- 769
I had a think about the code last night and came up with what's below. It uses Foob's code, but I think it is a bit simpler as it implements a 2 state machine, one benefit is that the switches don't need debouncing.
The 2 states are the stepper is stepping, or it's not.
If it's stepping, we only check the stop switch or the limit switches the stepper is moving towards. Direction switches are ignored, as is the limit switch the stepper is moving away from (this is to allow the stepper to move if it's sitting on a limit switch).
If it's stepping, and there's no stop condition, we check to see if we've moved the set distance, if so, we trigger the camera.
If it's not stepping, we only check the direction switches (and the limit switches to make sure we're moving off them), then change the state of the machine to "stepping".
Note I had to change the left limit switch to pin 7 as pin 5 wasn't working for me.
I think it just needs a bit of code to read the speed and distance pots.
Code:/* Ken's Camera Slider ** ------------------------------------------------------------------------------------------- ** Overview: ** Uses a stepper motor to move a camera along a slider, stopping at regular distance ** intervals. ** When the movement stops the camera should take a number of photographs, triggered by pin ** 13 on the arduino going high for a brief pulse. ** Direction of the stepper movement is controlled by 2 buttons, Left and Right (or forwards, ** backwards). ** The stepper motor can be stopped at any time by hitting a stop button, or by one of the ** limit switches triggering. Movement will not continue until a direction button is hit ** and the corresponding limit switch is not active. ** Distance for each interval is controlled by a potentiometer, as is speed of rotation. ** ** Hardware: ** Stepper Motor is connected to an Adafruit Motorshield V2, on motor connector 2 ** Camera trigger is connected to Digital output 13 ** All switches use the internal pullup and are connected between the corresponding pin and ** ground Switch Digital Pin Left - 2 Right - 4 Stop - 3 Left Limit- 7 Right Limit- 6 ** ** Required Libraries: ** Adafruit MotorShield V2 src: ** AccelStepper src: */ #include <Wire.h> #include <Adafruit_MotorShield.h> #include <AccelStepper.h> // Definitions: #define LEFT_PIN 2 // swap this with the RIGHT_PIN value if direction of rotation is not as intended #define RIGHT_PIN 4 #define STOP_PIN 3 #define LEFT_LIM_PIN 7 #define RIGHT_LIM_PIN 6 #define SPEED_PIN A0 #define DISTANCE_PIN A1 #define MAX_DISTANCE 2000 #define MAX_SPEED 250 #define MAX_ACCEL 150 #define CAMERA_PIN 13 #define CAMERA_PULSE 100 #define MAX_SHOTS 1 // define the maximum number of shots to be taken while stopped #define STEPS_PER_REV 200 #define STEP_TYPE SINGLE // you can change this to DOUBLE, SINGLE, INTERLEAVE or MICROSTEP to control the step type #define MAX_IDLE 500 // Global Variables: Adafruit_MotorShield AFMS=Adafruit_MotorShield(); // access to the motor shield using the default I2C address Adafruit_StepperMotor *motor1=AFMS.getStepper(STEPS_PER_REV,2); // connect to a stepper motor AccelStepper stepper1(forwardstep,backwardstep); // use functions to step // setup function just configures the hardware to be operating the way we want it to operate void setup() { Serial.begin(9600); // serial library will only be used for debug purposes - can safely be removed later Serial.println("Ken's Camera Slider"); AFMS.begin(); // connect to the motorshield using the default 1.6kHz frequency stepper1.setMaxSpeed(MAX_SPEED); // set default speed and acceleration for the accelstepper library stepper1.setAcceleration(MAX_ACCEL); pinMode(LEFT_PIN,INPUT_PULLUP); // set up the input pins pinMode(STOP_PIN,INPUT_PULLUP); pinMode(RIGHT_PIN,INPUT_PULLUP); pinMode(LEFT_LIM_PIN,INPUT_PULLUP); pinMode(RIGHT_LIM_PIN,INPUT_PULLUP); pinMode(CAMERA_PIN,OUTPUT); // and the output pin } void loop() { static char dir=0; static char stepping=0; static int stepspeed=0; static int stepdist=0; if (stepping) // Check to see if we should stop, check to see if the camera should be fired, run the stepper { if (digitalRead(STOP_PIN)==0 || (digitalRead(LEFT_LIM_PIN)==0 && dir==1) || (digitalRead(RIGHT_LIM_PIN)==0 && dir==-1)) { stepping=0; stepper1.moveTo(stepper1.currentPosition()); stepper1.run(); motor1->release(); dir=0; } else { if (stepper1.distanceToGo()==0) //Arrived at shooting point { delay(250); TrigCamera(); delay(100); UpdateDistance(stepdist,dir); } stepper1.run(); } } else // We're stopped. Check direction buttons to see if we should start, if so, set the speed and distance - these values could be read from pots. { if (digitalRead(LEFT_PIN)==0 && digitalRead(LEFT_LIM_PIN)==1) { dir=1; stepping=1; stepdist=500; stepspeed=250; UpdateDistance(stepdist,dir); } else if (digitalRead(RIGHT_PIN)==0 && digitalRead(RIGHT_LIM_PIN)==1) { dir=-1; stepping=1; stepdist=500; stepspeed=250; UpdateDistance(stepdist,dir); } } } void TrigCamera() { digitalWrite(CAMERA_PIN,HIGH); delay(CAMERA_PULSE); digitalWrite(CAMERA_PIN,LOW); } void UpdateDistance(int stepdist, char dir) { long newpos; newpos=stepper1.currentPosition() + (stepdist*dir); stepper1.moveTo(newpos); } // this function will be called by the AccelStepper every step the motor turns forward void forwardstep() { motor1->onestep(FORWARD, STEP_TYPE); } // this function will be called by the AccelStepper every step the motor turns backward void backwardstep() { motor1->onestep(BACKWARD, STEP_TYPE); }
-
11th April 2015, 10:48 AM #146SENIOR MEMBER
- Join Date
- Jun 2010
- Location
- Canberra
- Posts
- 769
So just to be clear on functionality, once the stepper is running, the 2 direction switches have no effect until the stepper is stopped.
Also, I was finding the stepper would stutter when the direction was changed after a stop, so I put this bit of code in for stopping the stepper:
Code:stepper1.moveTo(stepper1.currentPosition()); stepper1.run(); motor1->release();
-
11th April 2015, 01:55 PM #147Senior Member
- Join Date
- Nov 2008
- Location
- somewhere
- Posts
- 152
nice work rusty - much cleaner than mine.
-
11th April 2015, 04:17 PM #148Product designer retired
- Join Date
- Nov 2006
- Location
- Heidelberg, Victoria
- Age
- 79
- Posts
- 2,251
Camera slider update
Hi Rusty and foob,
Nice work Rusty, that seems to work fine. Thinking about the speed control, I don't think it's really necessary.
MICROSTEP gives nice little short bursts, SINGLE gives faster rotation and moves further.
Rusty, does it make any difference where your last little bit of code is inserted?
I tried inserting those few lines down near the bottom of the code, and got this error message
expected constructor, destructor, or type conversion before "token
Also I note that the camera shutter button keeps firing even when the motor is stopped via the stop button or limit switch.
Well done gentlemen!
Ken
-
11th April 2015, 09:20 PM #149SENIOR MEMBER
- Join Date
- Jun 2010
- Location
- Canberra
- Posts
- 769
That code fragment is already in the main code, you don't need to add it - I was kind of pointing it out to Foob in case he had any opinion on whether it was in fact correct, as I think he's actually read the doco for the stepper library.
-
11th April 2015, 10:51 PM #150Product designer retired
- Join Date
- Nov 2006
- Location
- Heidelberg, Victoria
- Age
- 79
- Posts
- 2,251
Camera slider update
Fair dinkum, I need new glasses. Rusty, I looked through your latest code mods and didn't recognize those last few lines of code you say were already incorporated.
A hugh thanks to foobillious and RustyArc for all the time and effort they have put into this project. I could not have done it on my own.
The sketch is brilliantly written giving me access to just about every parameter.
I am most grateful,
Ken
Similar Threads
-
Limit/home switches
By warrick in forum CNC MachinesReplies: 2Last Post: 7th July 2012, 08:11 PM -
Limit switches
By Bob Willson in forum CNC MachinesReplies: 0Last Post: 24th August 2011, 12:31 PM -
CNC Mill Limit Switches
By electrosteam in forum METALWORK FORUMReplies: 8Last Post: 10th September 2010, 07:31 PM -
How to Wire Limit switches on Xylotex board.
By Ch4iS in forum CNC MachinesReplies: 19Last Post: 19th October 2008, 09:58 PM -
Xylotex & limit/home switches
By John H in forum CNC MachinesReplies: 3Last Post: 31st July 2008, 08:08 PM