The ConditionCondition controls how long or how many times a while loop repeatsWhen condition is true, the while loop repeatsWhen condition is false, the while loop ends and the remainder of the program executesĬondition is checked every time loop repeats before commands between curly braces are runģ. The Word WhileEvery while loop begins with the keyword WhileĢ. Presentation NameCourse NameUnit # Lesson #.# Lesson Name21.
Would be good to add some comments to your code as well for clarity.While and If-Else LoopsROBOTC SoftwareWhile LoopsWhile loop is a structure within ROBOTCAllows a section of code to be repeated as long as a certain condition remains true You also have a typo at the top when you declare: int callown You can do the same for the following code as well: startMotor(mainMotor, 60) Īlso it seems like the while loop will never end because the value of x never changes. Here I'd write a function like the following: void adjust_sensors( size_t led, size_t level ) This is repeated with slightly different values. So in the large function called motors you have the following set of operations: int x = 1 The following code snippets I would make into separate functions. I'm not familiar with RobotC or VEX, however I've noticed a certain amount of replicated operations that could be made into their own functions. I do not know if it was a requirement for you.
It does not store up and down call while it is moving and go there later. Note : in this code the elevator will only take care of new up and down floor calls when the elevator is idle. we check if we trigger a floor switch and stop the elevator we check if a button is pressed and possibly go up or down Now, if we translate this into some pseudo code (which should be easily translated to RobotC) : enum elevator_status = The elevator is at a given floor and go from one floor to the other when it trigger a switch: Let's define what are the states of an elevator at a given moment: If (calldown = 1 & floorat = 1 & calldown = 0 || calldown = 1 & floorat = 1)Īlthough it shouldn't be a concern for this question, the 60 in the startMotor command is the speed of the motor, just to make it clearer. If (callup = 1 & floorat = 1 & calldown = 0 || callup = 1 & floorat = 1 & callup = 0)
If (SensorValue = 1 & floorat = 1)Įlse if (callup = 1 & floorat = 1) When the shaft sticking out the motor mechanism moves up and down, it presses limit switches and causes it to return a value of 1. The motor (mainMotor) rotates the gear which causes the mechanism to travel upwards on the slide. ) are analog buttons and return a value of 0 if not pressed and 1 if pressed. Could I possibly do anything to make this any simpler? Or better? I have attached a picture of my design that I made in AutoCAD Inventor with labels.įor those not familiar with RobotC or VEX (it is VERY similar to C and C++): the limit switches (limit1, limit2. I'm designing and programming an elevator-like robot for a high school project.