A few days ago, the HiTechnic Magnetic field sensor arrived at my doorstep. Ever since, I was thinking about what to use it for, and this is the result: an automatic binary encoder, sender, receiver and decoder used to synchronize two NXT motors. The video below shows the procedure:
So, the robot starts by setting the bias for the magnetic sensor before it’s near the magnet. Once the user adjusts the red stick to an acceptable angle (between 0 and 255 degrees – program is paused if angle is wrong) for the motors to sync to, that angle is translated into an eight-bit binary code. Then, the third motor compares its own position to the way it’s supposed to be – if a bit (boolean variable) is true, the black stud has to be up (0 degrees), and when the bit is false, the red stud has to be up (180 degrees). If necessary, the motor adjusts the position. At the same time, the magnetic field sensor “reads” the magnet, getting either a positive or negative number. If the received number is positive, it makes a bit true; if it’s negative, it makes that same bit false. Once it has all eight bits, it translates it back into a target for the other motor to go to, thus synchronizing the motors. At the very end, the third motor checks its position and makes sure it ends up having the black pin (north of the magnet) up.
More information:
- Magnetic Communicator code (word file – paste into RobotC)
Thanks to: