Emergency stop

This is a discussion on Emergency stop within the C Programming forums, part of the General Programming Boards category; If I wanted to add an emergency stop to an elevator programme should I use an if statement? Eg Code: ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    14

    Emergency stop

    If I wanted to add an emergency stop to an elevator programme should I use an if statement? Eg
    Code:
    If (emergency stop) 
     {
      Void main();
      }
    Or something along those lines?

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    There are many ways to do it. An if statement can do the job, but why you have void main there? You would probably want to use the exit function.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,163
    Stopping an elevator is also a markedly different concept from stopping the program that controls it.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    14
    Just put void main there as an example, should I put void and the name of my programme?

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    No.

    When we want to terminate a program because something went wrong, I would do this.

    If I was in the main, then I would do this
    Code:
    int main(void)
    {
         ....
         if(mustTerminate)
             return -1; // this usually shows that we did not terminate successfully 
         // DO WORK
         // Everything ok, thus return a zero
         return 0;
    }
    However, as you know, we use functions in programs and as a result, it is helpful to use exit function.
    Code:
    ...
    void someFunction(void)
    {
          if(somethingWentTerriblyWrong)
                exit(1);
    }
    BUT, consider reading again what grumpy said!!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,163
    No. Try it and see .... the compiler will complain bitterly and refuse to compile your program.

    Generally speaking, calling main() explicitly is usually a bad idea. There are certain cases where it is useful but, in practice, most programmers who try to call main() expect it to work differently than it actually does.

    And, if your C compiler is really a C++ compiler, calling main() is not allowed either.
    Right 98% of the time, and don't care about the other 3%.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    How about calling a function called say
    StopMotor();

    Then go onto the usual thing of waiting for another keypress from the elevator control panel (intercom, open doors, raise panic alarm).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Feb 2013
    Posts
    14
    Cheers guys, I'll give it a go at writing it either tonight or tomorrow after work and upload to see what you think and what could be improved

  9. #9
    Registered User
    Join Date
    Feb 2013
    Posts
    14
    Code:
    const int MAX = 5
    int data [MAX} = {0,1,2,3,4};
    
    
    // too many people in lift override stop motor and sound alarm
    void Liftcontrol
    	if (weight = 1)
    	{
    		motor1 = 0;
    		motor2 = 0;
    		alarm =1;
           }
           else
    {
    void main()
    		int index, temp;
    		Liftcontrol();
    		{
    			if(elevator = 1) //up elevator
    				{
    					if( data[index]  > temp) //if destination is above current floor go to floor
    						{ 
    						do
    						output to motor1 =1 for (input - current) seconds
    				 	      }
     					else
    						{
    						do
    						ADD input to queue until down elevator
    				 	        }
    		    		  }
    			if (elevator = 0) //down elevator
    				{
    					if( data [index] < temp) //if destination is below current floor go to floor
    						{ 
    						do
    						output to motor2 =1 for (current - input) seconds
    				 	      }
     					else
    						{
    						do
    						ADD input to queue until up elevator
    				 	      } 
         	               }
    		}
    this is what ive written so far, im using a 89s2051 controller, switches for inputs, an led display and a relay for the motor control, ill get the code as best as i can get in, create the circuit then add the pin numbers after, if this is the right way to go? or would you suggest getting the circuit made then the code?

  10. #10
    Registered User
    Join Date
    Feb 2013
    Posts
    14
    i want the elevator to start on floor 0 and return to floor 0 when there are no inputs but not sure how to create this loop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stop button doesnt stop a function (using PostMessage)
    By scwizzo in forum Windows Programming
    Replies: 7
    Last Post: 03-07-2008, 06:54 PM
  2. Emergency
    By taha54 in forum C Programming
    Replies: 8
    Last Post: 03-17-2006, 07:10 AM
  3. Emergency 2
    By newuser21 in forum C Programming
    Replies: 3
    Last Post: 03-12-2006, 08:04 AM
  4. Please help me with this !! Emergency
    By newuser21 in forum C Programming
    Replies: 1
    Last Post: 03-12-2006, 06:22 AM
  5. another novice need some emergency help
    By KarateKid in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2001, 10:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21