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.
#How to use robotc code#
The complete program is a bit fancier and includes some animation! You can watch the video below and download the source code here. move n-1 discs from auxillary to destination (sub problem) move n-1 disc from source to auxxilary (sub problem) This is the disc we're moving from one peg to another void hanoi( int N, tStack *source, tStack *dest, tStack *aux )
![how to use robotc how to use robotc](https://scobietech.files.wordpress.com/2014/12/robotc-1-2-samplecode.jpg)
This particular method uses recursion, another ROBOTC feature that was added in version 3.5, along with pointers. What it boils down to is that we’re going to use three stacks, one for each peg and we’ll use the pop() and push() functions to simulate taking rings off and putting them on another peg. The problem solving function was taken from here: and modified to make it work with ROBOTC. It’s described in great detail here:, so I am not going to spend a lot of time rehashing all that. Lucky for us, there’s a nice to way to solve this problem. A larger disc may never be on top of a smaller disc. Sounds easy, right? There’s a catch, though. Your job is to move these discs from the left peg to the right peg. You have three pegs and a bunch of increasingly smaller discs on the left peg. Tower of HanoiĪ cool way to use stacks is to play the Tower of Hanoi. This is generally frowned upon by purists. In the example, you’ll notice there’s also an operation called peek(), which allows you to inspect the top of the stack without actually popping the value. You can download the code with a simple demo program here. Decrement size and pop and value from the stack The last value pushed onto the stack is returned and the stack size is decremented. The pop() function is like the push() function in that we also pass a pointer to the tStack structure we wish to modify. Add the value to the stack and increment size WriteDebugStreamLine("Stack already at max size") After the new value is pushed onto the stack, the stack size is incremented. This way we can modify any stack we wish to pass to it.
![how to use robotc how to use robotc](https://www.dexterindustries.com/wp-content/uploads/2012/07/Step-Into-Debug-Stream-21.jpg)
Remember in the previous tutorial how we used pointers to allow us to modify a variable through another? This is the same thing, when we call the function push(), we pass a pointer to the stack we wish to push a new value onto. Note that the first argument of the function is a pointer to a tStack structure. If the stack is full, the function returns an error. The push() function initialises an element in the array that is next to the current top and increments the size of the stack. TStackElement elements // array of elements The stack elements can be easily put into a simple struct: // Individual stack element structĪll the stack needs to do is hold the elements in an array and keep track of the current size: // Stack struct to hold the elements Here is a simple drawing of the stack operations: The act of putting something on top is called a “push” and the act of taking something off is called a “pop”. You can do two things with a stack, you can either put something on top of it, or you can take something off. So what is a stack you ask yourself? Well, think of what a stack of things is in real life: a pile of items that you can only add things to, and remove things from the top. The CPU in your laptop or PC, your mobile phone and iPad all have one thing in common, they all use stacks, without exception.