elevator code for three floors

Go To Last Post
117 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes,    but it is a perfectly good exercise in Simulation.

 

What worries me is when people do not study the replies to their questions.

All the replies seem both sensible (and polite) to me.

 

Yes,    I often misinterpret a question.    And offer an answer to a completely different question !

 

We are all human.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP should be aware that most countries have very stringent safety regulations for lifts which have requirements which start before the design phase. For instance, in Europe we have 95/16/EC.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

+1 on Cliffs observation.

Here in NYC any of the elevator control systems I have seen that were installed in the last 20years use distributed processing(controller in car for buttons, another in the motor room for the heavy stuff, and a dispatcher professor to control multiple elevators).

 

I wonder if the OP is having this much trouble with three floors and just the call buttons how do you plan on controlling motor speed based on the variable loads(people) in the cars, the holding brake and the position reporter(usually a rotary encoder with a wheel touching a guide rail, or an optical switch with a performed strap that runs the length of the shaft).  Then there are the timers for door open times and the various key switches for independent, inspection, fire service. Then there is also the lobby control station too.

 

All of this is controlled using 32bit processors, not an 8bit AVR.

 

If this is not a school homework assignment, then can you provide some background as to your capabilities, and/or the group you are working with?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wikipedia has 16 completed buildings with 100 floors or more.

 

And 18 buildings that are still under construction.

 

So we can possibly guess which building the OP is designing for.     (Probably one of the ones on the list with 0 floors completed yet)

 

It is a perfectly good exercise to simulate an Elevator system.     I would guess that the algorithms change for the really tall skyscrapers.

All the same,    it is a complex subject.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

I'd suggest that real lifts use a 'scoreboard' rather than a fifo. Basically an array of size n floors each with a flag. When someone requests a floor, the flag for that floor is set. 

This is all fundamental stuff - if you're having trouble this means you're trying to run before you can walk. All this can be found on the interwebs - you really don't want us to do your homework do you?

 

Good point. the FIFO would not be optimal :P

scoreboard is an interesting concept. I would have just called is an array with a flag set for called floors.

And yes, someone is trying to save pennies here if it is a real elevator.

I mean really doesn't Otis etc have this figured out already???

Why is he trying to reinvent the elevator if it's not a class project.

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course it's homework. Strange that the OP won't admit it. Maybe they think they won't get an answer to a homework question?

On the other hand, I don't think there'll be much help forthcoming if we believe it's for a real elevator!

 

Even without the motor control, I'd think it's a pretty complex problem, as one would have to trade-off moving the elevator the minumum distance against the possibillity of starving a floor.

Four legs good, two legs bad, three legs stable.

Last Edited: Wed. Nov 12, 2014 - 03:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Look at it from the OP's point of view.

 

She has got a homework assignment and wants it to be completed by someone else.

 

If she admits that it is schoolwork,   no one will give a ready-made solution.

 

If she says that it is a hobbyist project,    she would get lots of assistance.

 

If she says that she is chief design engineer for Otis,    she just looks foolish.

 

Even if it is schoolwork,   she can still ask intelligent questions.     And will probably get good suggestions and advice to specific questions.

Of course,   all her classmates can see exactly the same replies.     It may irritate the teacher,   but this is the way that the real world works.      And yes,    the teacher will have a pretty good idea who has understood the question and understood how the solution works.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the last couple of weeks I've read an interesting article about elevator control algorithms and real ones have way more 'intelligent' algorithms than you might think. I can't for the life of me remember where it was though. It might have been in a trade mag but the 'library' had a clear out at the weekend.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
the 'library' had a clear out at the weekend.

You mean, the bin men have been...?

 

wink

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
real ones have way more 'intelligent' algorithms than you might think.

 

"it takes a great deal of effort to make something appear effortless"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is a school project then the complexity is minimal.

One gets to ignore all of the real world factors mentioned above, (redundancy, positioning, dynamic speed control, door safety, etc., etc.)

It turns into a simple simulation again.

Start at Floor 1 (or "Ground Level").

Wait for someone to push a button.

Go up and keep going up until you have reached the highest requested floor.

Then wait until someone pushes a down button, or a request is made from another floor.

If you have a down request, the elevator is now committed to down, and goes down until it reaches the lowest number anyone has requested.

If it was answering a call request, once again its direction has been committed from the requester, and it again starts up or down from the requester's floor.

 

This could be made into a really nice "simulation" with the push button switches and LEDs for floors all laid out correctly.

 

I love riding in real elevators with all glass walls so one can see the cabling, counterweights, rail systems, etc.

My wife doesn't like heights, and is terrified of riding in such elevators.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Floor 1 (or "Ground Level").

 

Floor 0, surely...?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i searched for bit array which put struct in my way, i found out some codes and i understand some, while my digging i found out that there is a bit field which can handle one byte . which mean 8 bits , so i can use it for my 8 floors . every bit will represent a single button.  i will try bit field for now then update to the higher level

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you want an interactive class in turning algorithms into code. Forget about elevators for a couple of days. The freaks will dream up simple little program specs, and you edit, compile, burn and run them them several times until you think they meet the spec, and submit them. Here's program spec 1: 2 momentary pushbuttons and 3 leds. Led 1 is on for 250ms, off for 750ms. Button 1 is software toggle that sets and resets a boolean variable in the program. Led 2 shows the output of the variable. Button 2 initiates a sequence on led 3 of on for 100ms, off for 200ms, repeat 3 times when pressed.

 

Imagecraft compiler user

Last Edited: Wed. Nov 12, 2014 - 07:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried this code in code vision 


#include <mega16.h>


/* define bit buffer array type*/
typedef struct { 
 unsigned char b0:1; 
 unsigned char b1:1; 
 unsigned char b2:1; 
 unsigned char b3:1; 
 unsigned char b4:1; 
 unsigned char b5:1; 
 unsigned char b6:1; 
 unsigned char b7:1; 
} bits_t; 

/* Set Bit Function */
void SetBit(bits_t* array, unsigned char loc, bit val)
{
    switch(loc)      /* loc has values in between 0 and 7 */
    {
    case 0: array->b0 = val; break;
    case 1: array->b1 = val; break;
    case 2: array->b2 = val; break;
    case 3: array->b3 = val; break;
    case 4: array->b4 = val; break;
    case 5: array->b5 = val; break;
    case 6: array->b6 = val; break;
    case 7: array->b7 = val; break;
    }
}

/* Get Bit Function */
bit GetBit(bits_t* array, unsigned char loc)
{
    bit result;

    switch(loc)        /* loc has values in between 0 and 7 */
    {
    case 0: result = array->b0; break;
    case 1: result = array->b1; break;
    case 2: result = array->b2; break;
    case 3: result = array->b3; break;
    case 4: result = array->b4; break;
    case 5: result = array->b5; break;
    case 6: result = array->b6; break;
    case 7: result = array->b7; break;
    }

    return result;
}

/* Main */
void main(void)
{
    unsigned char i;

    bits_t bit_array[10];               // Declare 10 bytes long bit array
	
	SetBit(&bit_array[1], 3, 1);      // Set bit3 of bit_array[1]

	if(GetBit(&bit_array[1], 3))	  // Check bit3 of bit_array[1]
		SetBit(&bit_array[1], 0, 1);  // Set bit0 of bit_array[1]

	for(i=0;i<8;i++)   // Use for loop to access the bits
		SetBit(&bit_array[0], i, 1);  	

	while(1)
	{}

but it give error , however every thing is ok

Error: C:\Users\madoo\Music\8051\new.c(18): 'bit' type not allowed in this context " referred bit val in Setbit function argu"

 

Last Edited: Wed. Nov 12, 2014 - 09:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You appear to be using Codevision.     You can return a bit from a function.     You cannot use bit as a parameter to a function.   So just make val a char or uint8_t.

 

The regular rules for type promotion will mean that you can pass a bit as an argument to the function.

 

I would try to do the project design in flowcharts or state machines.      Get your logic correct before you even think of coding.

 

If you are unsure of the coding,    just ask.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Never mind."  -- Emily Litella

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Wed. Nov 12, 2014 - 09:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado - writing the code before you've figured out the logic is working backwards. As David is apt to advise - get it working on paper first. Once you've got the process sorted out, writing the code is easy. Go for a ride in a real lift and see how it operates. 

Create 'rules'

eg: if going up and no more requests above and no requests below then park

if going up and next floor is requested then ....

if going down and no floors requested

 

if you lay out all the possibilities logically, your rules will be simple. Once you've got your set of rules, the code basically writes itself. The rules would also form part of your documentation that would earn brownie points with the teacher. 

Note: using an array of bits is a compact method. I would  have used an array of chars to simplify the process. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

You appear to be using Codevision.     You can return a bit from a function.     You cannot use bit as a parameter to a function.   So just make val a char or uint8_t.

 

David.

how to do val char or uint8 however it is a single bit ? it should be bit not char.

i tried to remove setbit function and compile getbit but error message said that

Error: C:\Users\madoo\Music\8051\new.c(21): functions can't return 'bit' type

 

Last Edited: Wed. Nov 12, 2014 - 09:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops.     I should have checked the docs first.

 

It looks as if you need to use char or unsigned char for the function parameter and return values.     Any promotion or truncation will happen transparently.

As Lee said,   bit is a non-standard extension.     It is an efficient way to store or access Boolean variables at the hardware level.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wasn't a chance to know about JTAG before so please simplify it.

If you don't know about JTAG and what it does please STOP YOUR PROJECT RIGHT NOW!!! You WILL KILL people.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

 

Note: using an array of bits is a compact method. I would  have used an array of chars to simplify the process. 

why array of chars however i just need 8 bits for 8 floors ? could you clarify your point ? do you intend to use them in any  stuff except buttons ?.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

wasn't a chance to know about JTAG before so please simplify it.

If you don't know about JTAG and what it does please STOP YOUR PROJECT RIGHT NOW!!! You WILL KILL people.

please i won't wake up in the morning to kill people i am trying to learn and train my self as this is my hobby . i will make a model  for my self so it will be real . if i stopped now because i don't know about jtag i won't learn any thing so please refer to a source to read about it and don't say stop.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado88,

 

Could you please get everyone one on the same playing field here by answering some basic questions?

 

1) What is your electrical/Electronic education and experience?

2) IS this a school project, hobby education, or a REAL system you are working on?

 

 

From reading your posts I am very confused.  The only way to get sound advice is a solid foundation.

 

Thanks

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wouldnt go to the trouble of packing booleans into bits until you have used 2041 bytes of your 2048 byte ram. Only then will those extra 7 bytes help you.

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

 

From reading your posts I am very confused.  The only way to get sound advice is a solid foundation.

 

 

tell me why are you confused ? i am just asking for help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado - download the datasheet for the AVR you are using and search for jtag. The answers are all there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

jgmdesign wrote:

 

 

From reading your posts I am very confused.  The only way to get sound advice is a solid foundation.

 

 

Is this for a real world application in a real building, or are you making an educational project?  THats what I meant, sorry.

 

tell me why are you confused ? i am just asking for help

 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

 

DocJC wrote:

Floor 1 (or "Ground Level").

 

 

Floor 0, surely...?

 

 

And then there's the danged mezzanine...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

Kartman wrote:

 

 

Note: using an array of bits is a compact method. I would  have used an array of chars to simplify the process. 

 

 

why array of chars however i just need 8 bits for 8 floors ? could you clarify your point ? do you intend to use them in any  stuff except buttons ?.

 

You need at least 2 bits per floor.  1 for UP_REQUEST, and 1 for DOWN_REQUEST.   You might also want a per-floor bit that goes active when the elevator is at the floor (not sure if that would be helpful, it just popped into my head).  Maybe also a bit that indicates floors that are locked out?  So don't prematurely optimize down to an array of single bits.  For one thing, C doesn't support it (although Ada does, and is available for AVR).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What concerns people here are a couple of statements you have made in the above threads. Like:

no, this isn't a homework.

 

why aren't you able to believe that it is a real elevator ,

 

so you are either learning, and it is therefore homework even if you are not attending a formal course OR, and this is the worrying point, you are designing and writing code for a real job in which case my comments above are valid.

 

I have been in electronics for just over 50 years now with more than 30 years using micros and I would be very hesitant taking on a job like this. I know that elevators have mechanical safety brakes in case of some failures but it is still an onerous task.

 

Going back to my JTAG comments you are using at least 3 of the 4 JTAG pins

#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

if JTAG is still enabled as the chip comes from the factory, those pins will do NOTHING in your code, in fact you are likely to DAMAGE the chip by using them, no one seems to be picking this up so I may be wrong.

 

JTAG is used to debug your code, so if you can spare another 3 pins for your buttons use them instead and leave pins C2-C5 for the debugger if you have one. If you don't have one I strongly suggest you get one and learn to use it. Others will have different ideas on this.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

JTAG is used to debug your code, so if you can spare another 3 pins for your buttons use them instead and leave pins C2-C5 for the debugger if you have one. If you don't have one I strongly suggest you get one and learn to use it. Others will have different ideas on this.

in simulation with Proteus it is working and there is no interference . i will need 16 inputs at least and also there will be outputs son i need all the ports pins , i will turnoff its fuse bits .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh boy, Proteus again!

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Proteus - it's what all the Indian students use! It's Labcenter's biggest market except they don't make any money from it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This popped up on the BBC News website a couple of days ago...

 

"The students who feel they have the right to cheat...Students are often keen to exercise their rights but recently there has been an interesting twist - some in India are talking about their right to cheat in university exams."

 

http://www.bbc.co.uk/news/magazi...

 

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the same must be happening over here as well - i've had to explain how to apply Ohm's Law to more than one recent electronic engineering graduate and had to demonstrate why you have to put a diode across a relay coil to another.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Floor 0, surely...?

I used to work for Amstrad in Brentwood. When they moved there they bought a building off Ford the US motor company (who own/employ about half of Brentwood it seems!). The curious thing about working in a building that belonged previously to Americans was that it had "American lifts". The floor at ground level was known as "1" not "G" as found in UK buildings. It often confused visitors who weren't familiar with the odd numbering our colonial cousins prefer.

 

I guess the original UK lift designers must really have been frustrated C programmers and preferred things to be 0 (or rather G) based ;-)

 

http://en.wikipedia.org/wiki/Sto...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a couple of customers in nyc who's floor numbers defy logic.  One such customer is on the 1st floor.  But that floor is six stories up as the real first six floors are open atrium of the lobby. Huh?

 

The other one I will never understand. The firm bought out floors 45 thru 49 of the building and have their own bank of elevators.  The street level is called Ground Floor, and the first stop on their elevator is floor 1.....45 stories up!  Their feeling is that's where their company's floors begin.

 

Money buys philosophy

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a couple of customers in nyc who's floor numbers defy logic.

How many of your customers have floor 13?  Remember that OP wants to extend the design to tall buildings -- is his elevator system always going to be "one floor off" once it gets higher?!?  ;)

 

 

Panel from an elevator in a residential apartment building in Shanghai. Floors 4, 13 and 14 are missing, because of the similarity between the pronunciation of the word 'four' and 'death' in Chinese; note also the "negative first floor", as the number zero is considered similarly unlucky in parts of East Asia.  (from Wikipedia)

OP was struggling with implementation of "bit mask" for floor representation earlier in the thread. Use this illustration for the prototype, and confusion will reign.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Nov 13, 2014 - 08:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried to use bit array inside sates but i failed i don't know how to use them. when some body call elevator to 4th floor it will go up before passing floor 1 somebody pressed  button one it should stop then complete its way to 4th . i couldn't do that inside states . do you have any idea?, also what would happen if it passed floor 1 then button 1 pressed , the elevator should go up and store button 1 to return to it while going down . in which state will this be implemented ? or i should write it outside switch cases

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We can only guess what your code does.

If you're going up and have passed floor 1 when someone has pressed 1, if there are requested floors above, you do them first then go down.

 

Again, create the rules then write the code. Or would you like us to write the code for you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I suppose that I have not used elevators very often.

 

THe obvious thing to do is "see how your University lifts work".

Then make your lift work in a similar way.

 

I would guess that if a lift has started going up,    it will service everyone that it meets on its upward journey (that wants to go up).

When they have all finished,   it will stop.

If there are any waiting customers,   it will go down serving any downward requests.    

Rinse and repeat.

 

This could mean that someone who has just missed the lift,   has to wait until it has completed a full return journey.

So a big building probably has more than one lift.

 

Of course,   you may have a better algorithm.

 

However you want to control the lifts,    you make your rules,   states,    flowcharts on paper.

You complete the design phase on paper before you even think of computer programming.

 

David.

Last Edited: Thu. Nov 13, 2014 - 09:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're going to have to do some sort of priority based traveling salesman algorithm. It's a non trivial implementation I'm sure, but I aint going to figure it out...

Prioritize by button press order, direction of travel, floors to service.

 

and what if theyre 2 cars, or more, being serviced by the same call button. We have 3 in my building.

It's a quite complex problem to do right and not end up with people just going up and down lol.

 

Looks like a fun problem. But one that requires a ton of design and useability testing.

 

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
You complete the design phase on paper before you even think of computer programming.

+999999

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It should be dawning by now that you actually have two distinct problems:

 

  1. Motion control - up/down; stop/start; doors open/close etc;
     
  2. Algorithm - how you will queue & service the lift requests.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and what if theyre 2 cars, or more, being serviced by the same call button.

In multi car systems there is a central controller called the Dispatcher that takes all the call buttons in, gets reports from the cabs as to their positions and call load and direction and then decides which car to send to the floor that called.  No easy task.

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folks want to go up to 10s of floors, but they all want to come down to the ground floor. I recall an article that solved the logjam to go up in the glass elevators at some big hotel. These 60+ year old synapses arent divulging much more info than that. I therefore claim that this info is lost forever and no-one will ever learn of this algorithm, or the hotel it is used in.

 

Imagecraft compiler user

Last Edited: Fri. Nov 14, 2014 - 03:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take the healthy option. Use the stairs.
 

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i changed state again to handle requests from 0 to 3 if button 4 pressed. i wrote it on paper before coding but elevator didn't stop .

if it is going to 4th floor and

if buton1 pressed then enter floor1 state

else if button 2 pressed then enter floor 2 state

else if button3 pressed then enter floor3 state

else floor 4 state

it didn't stop in any of the floors before 4th after the 4th button pressed .

 

pleased introduce a real help for this problem even a trigger to start with.

#include <mega16.h>
#include <delay.h>

#define BUTTON_0  PINC.0
#define BUTTON_1  PINC.1
#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

#define SENSOR_0  PIND.0
#define SENSOR_1  PIND.1
#define SENSOR_2  PIND.2
#define SENSOR_3  PIND.3
#define SENSOR_4  PIND.4
//////////////////////////
#define MOVE_UP    PORTB.1
#define MOVE_DOWN  PORTB.2
///////////////////////////////// 
enum elevator_state {
  PARKED_0,PARKED_1,PARKED_2 ,PARKED_3 , PARKED_4  ,
  f1   , f2  , f3   , f4  
  };  
  ///////////////////////////////
  unsigned char state = PARKED_0;
////////////////////////////////////
   void main(void)
{
PORTB=0x00;DDRB=0xFF;
PORTC=0x00;DDRC=0x00;
PORTD=0x00;DDRD=0x00;
  for( ;; ) {
  	
  	switch( state ) {
  case PARKED_0:    // parked at floor 0 
     if (BUTTON_4|BUTTON_3|BUTTON_2){
         delay_us(10);

        PORTB.1=1;  // motor up 
       state=PARKED_1;
       } 
             break;

     case PARKED_1:
     
         if( BUTTON_1){
         delay_us(10);
         state=f1;        
         }  
         else{
         state=PARKED_2;
         }  
             break;

       case PARKED_2:
    
          if(BUTTON_2){
         state=f2;
         }
         else{
         state=PARKED_3;
         }
        break;
  
     case PARKED_3:
  
         if (BUTTON_3){
         state=f3; 
         } 

         else{
         state=f4;}
         
      break;
    case f1:
         if (SENSOR_1){
           PORTB.1=0;  // motor stop
           }
           break;
     case f2:
         if (SENSOR_2){
           PORTB.1=0;  // motor stop
           }
           break;
     case f3: 
         if (SENSOR_3){
           PORTB.1=0;  // motor stop
           } 
   break;
      case f4:
         if (SENSOR_4){
           PORTB.1=0;  // motor stop
           } 
     break;
       }
   }   
   }
   

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

real help?

You're SM is wrong, make it right.

the Sm should not know what floor it's on

Keith Vasilakes

Firmware engineer

Minnesota

Pages