This Lizard is a creation from the book "The Unofficial LEGO MINDSTORMS NXT 2.0 Inventor's Guide, 2nd Edition" by Laurens Valk and David J. Perdue. Below is a video clip demonstrating the "Walking", "Object Detection" and "Turning" functionalities of the Lizard for the code snippet provided in LeJOS.
Let me explain the code functionality. The code has a single class MovLizard which has the main method. The main method is responsible for Walking, Object Detection and Turning functions of the Lizard. However before explaining the code, I need to explain some important points of the Lizard's assembly which matter for our software.
- The Lizard is built with two touch sensors which are connected to its legs assembly such that when each of the touch sensors gets pressed the front and back legs get synchronized. By synchronized, I mean the front and back legs coordinate with each other very well. The front-right and back-left legs move forward at a time. And front-left and back-right legs move forward the next time.
- The Lizard is also built with an ultrasonic sensor which allows it to detect an object placed in front of it.
The main program starts with an initWalk function which invokes synchronize function. The synchronize function rotates motor A and motor B until the touch sensor A and touch sensor B gets pressed respectively. The motors stop when the touch sensor gets pressed. The initWalk function then rotates motor B to make the touch sensor B un-pressed and get the Lizard to start walking.
The main program then starts both the motors A and B in a continuous while loop. Apart from running the motors the while loop also checks whether there is an object within a distance of 30 cm. If an object is detected, the Lizard synchronizes itself again. It takes an approximate 90 degrees turn by stopping motor A and keeping other motor B running for around 25 seconds. If we want an exact 90 degrees turn, we can also attach a gyro-sensor with the Lizard assembly. However, currently there is no gyro-sensor on the lizard. So, once the turn is completed, the initWalk method is called again to synchronize the legs. The Lizard changes its course of movement and starts walking in a direction 90 degrees to the previous one.
No comments:
Post a Comment