Pages: 1 [2] 3   Go Down
Author Topic: help micro elevator code  (Read 3036 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes and also my code compile, but its 100% my code doesnt work.... it need tobe changed
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25874
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, you need to fix the problems already pointed out.
Then you need to run it, and figure out what it is that it does that you didn't expect it to, and what it didn't do that you did expect it to.
Debug prints are useful for this.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes i now, but i can test it till tomorrow when the stepper driver its ready, but i need to know now how can i make the stepper to run without tellihn how many steps i need to move it
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
reading the state of the pins would be like this right
Yes, but...

Later in your code, what does val1 mean? Could you infer what floorSwitchState1 meant? Which is easier to understand?

Now, it makes no difference to the compiler. Everything is translated to a memory address as far as the compiler is concerned. But, long before the compiler has spent a few seconds with your code, you (and we) will have spent hours trying to understand what it is doing. Why not make it easy on yourself and use meaningful names?
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 46
Posts: 2865
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could this be a case of the elevator not going all the way to the top?

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Could this be a case of the elevator not going all the way to the top?

With all those misplaced semicolons anything can happen.
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

val1 its the variable for reading the pin status.....

this its taken from this tutorial for push buttomshttp://www.arduino.cc/en/Tutorial/Pushbutton....

Floor ist obvious the floor counter, for arduino to "know" which floor its,
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

val1 its the variable for reading the pin status.....

this its taken from this tutorial for push buttomshttp://www.arduino.cc/en/Tutorial/Pushbutton....

Floor ist obvious the floor counter, for arduino to "know" which floor its,


the semicolosn where remove from the code...

this its the code for now:
Code:

/*
 Stepper elevator Control -
 
 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 10-11 of the Arduino.
 
 The push buttoms selects the floor and the stepper spin till
 the hall sensor its trigger enough ties o reach the floor the push buttoms selects.
 
 
 
 
 Created 18 Nov. 2012
 by Cesar flores
 
 */

#include <Stepper.h>
   
const int stepsPerRevolution = 200; 
const int  Floor1 = 2;
const int  Floor2 = 3;
const int  Floor3 = 4;
const int  Floor4 = 5;
int val1= 0;
int val2= 0;
int val3= 0;
int val4= 0;

// initialize the stepper library on pins 10 11:
Stepper myStepper(stepsPerRevolution, 10,11);           
int hallcount=0;
int Floor = 1;         // the floor the elvator its

void setup() {
  attachInterrupt(0, hall_count, RISING);// initialize the hall effect sensor pin as an interrupt
 myStepper.setSpeed(30);

 pinMode(Floor1, INPUT);
 pinMode(Floor2, INPUT);
 pinMode(Floor3, INPUT);
 pinMode(Floor4, INPUT);
}

void loop() {
  val1=digitalRead(Floor1);
  val2=digitalRead(Floor2);
  val3=digitalRead(Floor3);
  val4=digitalRead(Floor4);
 
 


  switch (Floor)
  {
  case 1:
  {if (Floor==1 && val1==HIGH)
  {
 
    myStepper.step(0);
   
   Floor=Floor;
  }
  if(Floor==1 && val2==HIGH)
  {
  myStepper.step(400);//here its my problem i want to move the stepper till its reach the hall sensor
  Floor++; 
 
  }
  if(Floor==1 && val3==HIGH)
  {
   myStepper.step(400);
  Floor=Floor+2;
 
  }
  if(Floor==1 && val4==HIGH)
  {
    myStepper.step(400);
   Floor=Floor+3;
 
}
  }
break;


 
 
 
  case 2:
  {if (Floor==2 && val1==HIGH)
  {
   myStepper.step(400);
   
    Floor--;
  }
  if(Floor==2 && val2==HIGH)
  {
  myStepper.step(400);
  Floor=Floor;
  }
  if(Floor==2 && val3==HIGH)
  {
   myStepper.step(400);
  Floor++;
  }
  if(Floor==2 && val4==HIGH)
  {
    myStepper.step(400);
   Floor=Floor+2;
  }
  }
  break;
 
 
  case 3:
  {if (Floor==3 && val1==HIGH)
  {
   myStepper.step(400);
   
   Floor=Floor-2;
  }
  if(Floor==3 && val2==HIGH)
  {
  myStepper.step(400);
  Floor--; 
  }
  if(Floor==3 && val3==HIGH)
  {
   myStepper.step(400);
  Floor=Floor;
  }
  if(Floor==3 && val4==HIGH)
  {
    myStepper.step(400);
   Floor++;
  }
  }
  break;
 
  case 4:
  {if (Floor==4 && val1==HIGH)
  {
  myStepper.step(400);
   
   Floor=Floor-3;
  }
  if(Floor==4 && val2==HIGH)
  {
  myStepper.step(400);
  Floor=Floor-2;
  }
  if(Floor==4 && val3==HIGH)
  {
   myStepper.step(400);
   
   
  Floor=Floor-1;
  }
  if(Floor==1 && val4==HIGH)
  {
  myStepper.step(400); 
   Floor=Floor;
  }
  }
  break;
 
 
  } 
}

void hall_count()
 {
   hallcount++;}
   //, this interrupt function is run once when the elevator passes the magnets on each floor

« Last Edit: November 18, 2012, 08:14:51 pm by copachino » Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
reading the state of the pins would be like this right
Yes, but...

Could you infer what floorSwitchState1 meant? Which is easier to understand?

do you mean the state of the floor??? its the floor number there its only 4 floor, so for the first time the floor will be on floor one, the counter Floor will let decide which option will take the elevator depending on the state of the push buttons, the idea its that when depending on wich floor the elvator its, and also depending on which push button its pressed the program will decide the direction and how many times the hall sensor needs to be passed
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are testing (all?) the combinations between the target floor and the current floor. I suggest you write code that calculates the current floor based on val1..4 values. Then you can just look at the difference between where you are and where you want to be.

Like:

if val1 == HIGH
    currFloor = 1
etc.

distance = currFloor - targetFloor;

if distance == 0
  stop
else
  set motor direction based on the sign of distance
  move motor of (stepsPerFloor * abs(distance)) steps
endif
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

in fact as you can see i dont need the if(Floor==1) i can be only testing the digital read as if(val1==HIGH).....
that was the main doubt i had, am used to program in c++(and this its not c++), so im not sure tha if i select the variable Floor for the switch sentence its ok, or its the biggest mistake on the code, because i am using the memory of the counter Floor for the program to decide de case,
for example in case 1: the counter Floor values 1, and depending on the state of the buttons i get the direction of the stepper..



Code:
{
  case 1:
  {if (val1==HIGH)
  {
 
    myStepper.step(0);
   
   Floor=Floor;
  }
  if(val2==HIGH)
  {
  myStepper.step(400);//here its my problem i want to move the stepper till its reach the hall sensor
  Floor++; 
 
  }
  if(val3==HIGH)
  {
   myStepper.step(400);
  Floor=Floor+2;
 
  }
  if(val4==HIGH)
  {
    myStepper.step(400);
   Floor=Floor+3;
 
}
  }
break;
« Last Edit: November 18, 2012, 09:11:20 pm by copachino » Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

_now_ you're not testing Floor==1. You were in the last code you posted.

Oh, btw, that looks like (terrible) C++ to me. Would you please enlighten me as to which language it _really_ is instead ? smiley-razz
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it was supposed on c++, but i said i am terrible programming...

but i dont need to test the Floor am in because that its the job of the counter Floor, as you can see it increments or decrements depending on haw many floors the elvator moves.... but the main problem its to implement a routine, that when the elevator its on move, untill this routine finish the elevator wont change the direction when a buttom pin changes its state...
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

why don't you keep the motor stepping in small increments until the switch for the target floor activates?

Like:

while switch of target floor is off
    step motor for 10 steps
end while

or maybe there's a "continuous move" function in the stepper library... I don't know that lib very well still...
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 341
UNO
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i know there was a mod stepper library tha includled the STOP, CCW and CW movement, but i cant find it now jejeje... the steper moves really slow...


also do you think that for this moment, the switch(Floor) and the "if" inside the cases are well programmed??, i suck so much that i can even tell that.... the whole idea with the sensor its also use a counter hall, as i said sometimes it need tobe triggered more than once to reach a floor, so that what i need the hall_counter, but, im havng problems with that because i need that the hall_counter reset to zero every time the stepper moves
Logged

Pages: 1 [2] 3   Go Up
Jump to: