Pages: [1]   Go Down
Author Topic: Pan and Tilt  (Read 209 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I am making a pan and tilt gimble that will make sweeping scans left to right and moving down a notch after each left to right movement.
Accuracy is not important and all movement is stopped when a button is pressed hence the use of delay while motors are running
I have hall effect and incremental rotary encoders to hand but that would be over kill for this project .
I have come up with the following code which seems rather repetitive and looking at making it shorter and cutting it down to a couple of lines.
Can anyone please advise.
Code:
#include <AFMotor.h>
#include <Button.h>
Button button = Button(12,PULLUP);
AF_DCMotor motor(4);
AF_DCMotor motor2(2);
void setup() {

}

void loop() {
 if(button.isPressed()){
   motor.run(RELEASE);
 }else{
   motor.run(FORWARD);
   delay(5000);
   motor.run(BACKWARD);
   delay(5000);
   motor.run(RELEASE);
   motor2.run(FORWARD);
   delay(1000);
   motor2.run(RELEASE);
   motor.run(FORWARD);
   delay(5000);
   motor.run(BACKWARD);
   delay(5000);
   motor.run(RELEASE);
   motor2.run(FORWARD);
   delay(1000);
   motor2.run(RELEASE);
   motor.run(FORWARD);
   delay(5000);
   motor.run(BACKWARD);
   delay(5000);
   motor.run(RELEASE);
   motor2.run(FORWARD);
   delay(1000);
   motor2.run(RELEASE);
   motor.run(FORWARD);
   delay(5000);
   motor.run(BACKWARD);
   delay(5000);
   motor.run(RELEASE);
   motor2.run(FORWARD);
   delay(1000);
   motor2.run(RELEASE);
  
 }
}
« Last Edit: March 18, 2014, 08:16:29 am by andi968 » Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 7
Posts: 1545
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

get the code under hash "#" tags please!
Logged

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੂਂ !

UK
Offline Offline
Faraday Member
**
Karma: 47
Posts: 3504
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First get rid of ALL the delay()s.  See the Blink Without Delay example sketch for the proper way to do timing.

If you want to perform a preset series of movements you could define the series as an array of characters such as
Code:
char movements[] = {'f', 'b', 'r', 'f', 'r', 'f'}
etc - where f = fwd, b = bkwd and r = release

Then in loop() you would have something like this (assuming there are 6 steps in the series)

Code:
for (int n = 0; n < 6; n++) {
   motorRun(movements[n]);
}

The code I posted in Reply #15  of this Thread may be of interest http://forum.arduino.cc/index.php?topic=226331.msg1639662#msg1639662 may be of interest.

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many thanks for that and reference to the other post.
How would the sketch look in total ( I am still learning Arduino) would you mind showing me a bit more
Logged

UK
Offline Offline
Faraday Member
**
Karma: 47
Posts: 3504
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very like the sketch in the other Thread except that you would control servos instead of leds.

You have two different motors and I don't understand how their movements are coordinated. Maybe you need to use (for example) 'f' to mean one motor and 'F' to mean the other.

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

motor is for left to right axis and motor2 is for up and down
I have tried with simple servo and continuos servo but they can not supply the torque required hence adafruit motor shield and motors with gearbox.
Logged

Pages: [1]   Go Up
Jump to: