Projects for NXT 2.0 - NXT Programs Projects for NXT 1.0 Amazon.it: LEGO MINDSTORMS. 2: Tribot Line Follower 0:40 3: Time Lapse Disassemble and Build 1:0. NXT 2.0 Scorpion: This is my nxt 2.0 scorpion i made, it is fighting a sphero!
Reading S'ensors
![Nxt Programs For Tribot Fighter Nxt Programs For Tribot Fighter](/uploads/1/2/6/2/126293246/999495330.jpg)
In Building Robots with LEGO Mindstorms NXT, 2007
The Servo Motor Encoder (Rotation Sensor)
The legacy RCX rotation sensor was always known for its lack of reliability with readings when turning at both low and high speeds. Robot makers had to play with code to provide stability to readings returned from this sensor.
LEGO decided to integrate an encoder (rotation sensor) directly within its new NXT servo motors (Figure 4.10). There are two benefits to this: The encoder functionality was improved, and the NXT received three rotation sensors built right into the motors that don't require additional sensor ports! The interactive servo motor (as it's also referred to) allows you to measure both speed and distance in a variety of formats, including degrees, rotations, and seconds. It acts as both a motor and a rotation sensor, and has a dedicated block for each of these in NXT-G. In RobotC, you would simply set the parameters for driving the motor as you normally would while using other commands to read the encoder values to measure rotation.
Figure 4.11 shows an internal view of the servo motor with the encoder (in blue) located to the left of the larger orange drum (the motor). In reality, the encoder is actually a black wheel that contains 12 holes which allow the optical sensor to read 24 on/off states with each full rotation. This provides the NXT with a great deal of resolution to detect position down to the nearest degree. From the image, you can also see how the NXT motor is internally geared. There is enough torque to drive wheels/tracks directly. Even though the RIS motors are also internally geared, they have limited torque that usually required an additional geartrain—especially in sumo competitions!
Having an encoder built directly into the servo motor allows robot designers to develop more sophisticated drive mechanisms that enable your robot to do things such as drive straight, even over rough terrain. This functionality works out of the box with NXT-G. When you program your robot, the move block pairs two motors together, enabling the NXT to monitor the encoders of both motors while correcting them on the fly to ensure that the robot is tracking straight. The general idea is that the program monitors rotations on both motors. If one falls behind, it adjusts the speed of one motor to compensate for the lag, which keeps the robot driving straight.
You can try this yourself by creating the TriBot from within Robo Center (sample robots in NXT-G). Following the programming guide, you will use a move block to allow for both drive motors to be synchronized. Once built, run the robot and follow along beside it. Press your finger to one of the wheels and then let go. Note how at first you slow down one side of the robot, but then it speeds that side up to bring the robot back to driving in a straight line.
As mentioned earlier, you can use a single servo motor to both move an elevator as well as determine which floor it is on. With the new level of accuracy in these motors, you can determine the position of the elevator by performing some simple tests to find which angle values represent each floor. To do this, create the elevator unit and manually rotate the motor while viewing the encoder rotation values in NXT-G (or the RobotC poll brick window). Jot down the rotation angle for each floor. Then, simply identify in your program these angles as stop points for the elevator unit.
The encoder functionality is very powerful for the future of NXT robots, as it opens the door by enabling your robots to be “location-aware” by performing tasks such as room mapping. The sky is the limit here.
Bricks & Chips …
How the Servo Motor Encoder Works
The NXT motor encoder detects movement similar to the way an older computer mouse (with the ball) works. One of the first things Philippe Hurbain (Philo) did when he got his NXT set was to dismantle the servo motors to have a look under the hood. His site (see Appendix A) provides detail on this. Figure 4.12 shows the motor and encoder components cut away from the rest of the motor. The encoder wheel (the black wheel to the right) is driven directly off the motor. The wheel has a number of holes in it which allow the optical sensor to detect on/off states as it spins. A beam of light is generated from the optical sensor (the gray square box covering the encoder wheel) on one side of the encoder wheel and shines through to the other, which falls upon a photocell. As the motor spins, the encoder rotates and causes light to alternate through a series of on/off states. The sensor picks this up and passes the information to the NXT for processing. Unlike the older rotation sensor, because the motor is directly coupled to the encoder wheel, direction is automatically handled, as the NXT always knows which way it is driving the motor based on the programming done in the software.
Through RobotC, it is possible to detect motor stall conditions by monitoring the motor encoder rotation as your motor turns. Knowing the power and expected output of the motor, you can match this with the speed at which the encoder is actually turning and detect when the motor has stopped turning. This has an added bonus, as you could conceivably create a robot that does not need a touch sensor to detect when it has hit a wall. You can simply monitor the motor rotations and judge it this way—when you hit a wall, you can detect that the motors have either slowed or stopped, and after a period of, say, one or two seconds, force a decision to back up or turn.
NOTE
The NXT supports three types of sensors: passive, active, and digital. The main difference is that passive sensors do not require a current generator to supply power to the sensor, whereas active sensors do. Digital sensors use l2C communication and typically have a microcontroller to handle sampling of the environment.
Passive sensors include the touch sensor (NXT and RCX), light and sound sensors (NXT), and the RCX temperature sensor. Active sensors include the RCX light and rotation sensors. Digital sensors include the NXT ultrasonic sensor and numerous third-party sensors such as color, compass, pressure, gyro, and acceleration sensors.