As described in the previous post (“Plans for Lego World 2016”), the updated crane uses two touch sensors for the positioning of the hoist. In this article, I explain this in more detail.
The two sensors slide over two rails that makes sure that they are pressed or released. By this means, we can distinguish four positions that are shown in the picture below:
The numbers 1 to 3 are ‘defined’ positions:
1. Pickup position where the container is picked up from the conveyor belt.
2. Loading position #1 where the container is loaded into the train at track 1
3. Same as previous, but then for track 2.
Position 4 defines ‘the rest’, that is any position between the defined numbers and left from position 3. But note that there is no position 4 at the right from position 1. This is important for determining the starting position: when starting up the EV3 of the hoist, the EV3 can determine if it is on position 1, 2, 3 or 4 based on the state of the two touch sensors. In case of position 4, it is not exactly defined. But one thing is certain: if the hoist moves to the right, it will eventually find position 1. That is the reason that there is no position 4 at the right of position 1. Otherwise we wouldn’t know at startup in what direction the hoist should move to one of the defined positions.
So, the first thing to do when starting up: move the hoist to position 1 by moving to the right until it finds that sensor 1 is pressed and sensor 2 is released. From that moment, it is easy: if the hoist has to move to one of the three defined locations:
- if the new position > current position: move to the left
- if the new position < current position: move to the right.
And keep on moving, until the touch sensors indicate that you have reached the desired position:
- Touch sensor 1 = pressed and Touch sensor 2 = released
- Touch sensor 1 = released and Touch sensor 2 = pressed
- Touch sensor 1 = released and Touch sensor 2 = released
A demo program that randomly chooses the new position, has proven that the touch sensor readings are very accurate and that it never failed to miss a location. If you are interested in the EV3 program, please drop me a note.