Coding Outline
The following is the outline that I wrote for my code when we were in the planning phase, it is only a rough outline of what I planned to do:
Clear Timer;while(1==1){ if(switch1 || timer > 5000 || switch4){ stop floor 2 led stop floor 3 led start floor 1 led go to floor 1 clear timer } if(switch 2 || switch 5){ stop floor 1 led; start floor 2 led; stop floor 3 led; go to floor 2 clear timer } if(switch 3 || switch 6){ stop floor 1 led; stop floor 1 led; start floor 3 led; }}public void gotofloor1{ start motor wait until sonar value < 2 stop motor}public void gotofloor2{ start motor wait until sonar value < 4 stop motor}public void gotofloor3{ start motor wait until sonar value > 4 stop motor}Code
The following is the code that I wrote for the machine:
#pragma config(Sensor, dgtl1, switch1, sensorTouch)#pragma config(Sensor, dgtl2, switch2, sensorTouch)#pragma config(Sensor, dgtl3, switch3, sensorTouch)#pragma config(Sensor, dgtl4, switch4, sensorTouch)#pragma config(Sensor, dgtl5, switch5, sensorTouch)#pragma config(Sensor, dgtl6, switch6, sensorTouch)#pragma config(Sensor, dgtl7, sonar, sensorSONAR_inch)#pragma config(Sensor, dgtl9, yellow1, sensorLEDtoVCC)#pragma config(Sensor, dgtl10, yellow, sensorLEDtoVCC)#pragma config(Sensor, dgtl12, red, sensorLEDtoVCC)#pragma config(Motor, port9, upMotor, tmotorVex393_MC29, openLoop)//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*///* Project Title: Project 3.1.7 Team Members: Dhanvi M Date:3/1 Section:1 Task Description:A company would like to begin producing residential elevators. Your team must design the control system and a prototype of an elevator that can go between three floors in any combination. The prototype must include a set of three switches to represent each floor of the elevator. Each floor the elevator stops at must have a call button and a set of three lights to indicate where the elevator is currently located. A built-in safety mechanism requires that the elevator normally rest on the ground floor and return to the ground floor after a user-determined period of nonuse. Pseudocode: If the two buttons that send the elevator to floor 1, turn on the corresponding leds and send the elevator there If the two buttons that send the elevator to floor 2, turn on the corresponding leds and send the elevator there If the two buttons that send the elevator to floor 3, turn on the corresponding leds and send the elevator there If the elevator is not used for 5 minutes then the elevator will go back to floor 1*/int floornum = 1;void goToFloor1(){ //function definition SensorValue(yellow) = false; SensorValue(yellow1) = false; SensorValue(red)= false;//turns LEDs on and off if(floornum != 1){ startMotor(upMotor, 30); //starts motor //wait(2); waitUntil(SensorValue[sonar] == 2); //waits until carriage is at the right floor stopMotor(upMotor); //stops motar } floornum = 1; //sets variable to floor}void goToFloor2(){ //function definition SensorValue(yellow) = false; SensorValue(yellow1) = false; SensorValue(red)= true;//turns LEDs on and off if(floornum !=2){ if(floornum == 1){ startMotor(upMotor, -30); //starts motor one way if on floor 1 } if(floornum == 3){ startMotor(upMotor, 30); //start motor the other way if on floor 3 } waitUntil(SensorValue[sonar] == 5); //waits until carriage is at the right floor //wait(1); stopMotor(upMotor); //stops motar } floornum = 2; //sets variable to floor}void goToFloor3(){ //function definition SensorValue(yellow1) = true; SensorValue(yellow) = true; SensorValue(red)= false;//turns LEDs on and off if(floornum != 3){ startMotor(upMotor, -30); //starts motor //wait(2); waitUntil(SensorValue[sonar] == 7); //waits until carriage is at the right floor stopMotor(upMotor); //stops motar } floornum = 3; //sets variable to floor}task main(){ clearTimer(T1); if(SensorValue(sonar) == 2){ //assigns the initial floor the right value; floornum = 1; } if(SensorValue(sonar) == 5){ floornum = 2; } if(SensorValue(sonar) == 7){ floornum = 3; } while(1 ==1){ if(SensorValue(switch1) == 1 || SensorValue(switch2) == 1 || time1(T1) > 10000){//if corresponding buttons are pressed or timer runs up goToFloor1();//goes to the right floor clearTimer(T1);//clears timer } if(SensorValue(switch3) == 1 || SensorValue(switch4) == 1){//if corresponding buttons are pressed goToFloor2();//goes to the right floor clearTimer(T1);//clears timer } if(SensorValue(switch5) == 1 || SensorValue(switch6) == 1){//if corresponding buttons are pressed goToFloor3();//goes to the right floor clearTimer(T1);//clears timer } }}Video
Conclusion Questions
1. Describe the Objectives for this project in your own words
Create an elevator, the elevator much be able to go to 3 different floors. Each of the floors should have a call button, and there should 3 go buttons inside the elevator. Each floor should have 3 leds, each led representing a different floor. After a set amount of time the elevator should return to the first floor.
2.What were the most difficult parts of the problem? Describe the difficulties you had with there things
The most difficult part of this problem was getting the LED lights to work, the problem mostly stemmed from problems with hardware. In our case, the LEDs from port 11(1st Floor) would not turn off, even if we stopped the program. We removed the third set of LEDs to fix this, and used the other two leds to indicate if the carriage was on the first floor.
3.List and describe two features that were not part of the design problem that could be added to impove your design
If we could add two doors for each level then the elevator could be more realistic, we were actually planning on doing this but decided to drop it because of time restrictions. Another think we could do is store button clicks, so if the carriage is on floor 1 and the floor 2 and 3 buttons are pressed the carriage would stop at both floors 2 and 3.
4.Describe how your design and program worked during the official test? Was your design successful? Why or why not?
During the official test our design perfectly. Everything we intended for it to do worked, so our design was a success.
5.Describe some things you learned during this project
I learned that the Sonar Sensor Value has an approximately 1 inch tolerance when measuring distance in inches. I also got a deeper understanding of what parts were in my kit, and how to work around having limited parts.