8/22/2021

How To Program An Nxt Segway Labviewlasopafs

20

Fun Projects for your LEGO® MINDSTORMS® NXT!

NXT Segway with Rider
Building:
Program:

NXT Segway with Rider: Building: Program: This robot simulates a Segway PT, which is a two-wheeled self-balancing vehicle that a rider stands on. By using the NXT light sensor as a simple proximity sensor to the ground to detect the approximate tilt angle of the robot, the robot can actually balance itself! The NXC code can be compiled using the free Brixcc programming environment for windows. The following option must be set: Edit Preferences Compiler NBC/NXC Optimization Level 1. When either the NXTWay or AnotherWay program is started on the NXT, the NXT must be placed motionless on a surface so that the gyro semsor may be calibrated. Connection from the second NXT (the remote control) to the Segway NXT on Connection 1, then run the SegwayRemoteprogram on the remote control NXT and the SegwayBTprogram on the Segway NXT, starting with the Segway balanced. Now pressing the gray Left and Right. Today I want to share with you a video of segway robot (called Gyroboy) that I built recently. It’s actually quite simple to build this self-balancing robot. As I mentioned earlier, Lego offers two series of Mindstorms, regular Mindstorms and Mindstorms Education.

Building Instructions

1

OR

You can use the NXT with either AA batteries or the NXT Rechargeable Battery Pack.

2

How to program an nxt segway labviewlasopafs plus

3

4

5

Segway
Insert the cross brace between the motors, keeping the wires routed under it as shown above. Wrap and then connect the B and C wires to the two motors as shown below, then finally attach the color sensor as shown, which should be connected to the port 3 wire.

6

7

8

9

10

How

11

12

Connect the body motor for the rider to port A. The ultrasonic sensor is not attached in this design.
NXT Segway with Rider Programming

Important Usage Information

Note: Unlike balancing robots that use a gyroscopic sensor or other special sensors, this design uses only the color sensor, which does not know which way is 'up' in an absolute sense, so it can only guess on its relative tilt based on the amount of reflected light received from the ground. As a result, getting a good balance is a bit of a challenge when you are using it. Please read the following important tips.

Getting the NXT Segway with Rider robot to balance requires good lighting and surface conditions for the color sensor, and also requires that you start the robot exactly balanced to begin with, so be prepared to experiment with different surfaces and lighting, and also some practice at getting the robot started out balanced to begin with. Here are some tips:

  • Lighting. External (room) lights can confuse the color sensor, especially if the amount of lighting or shadow varies as the robot moves around. For best results, find a location where the color sensor will be in shadow from any room lights, even as the robot moves forward and backward by a couple of feet in either direction. Also, florescent lights will interfere less than incandescent lights. In particular, make sure that when you remove your hand(s) to release the robot in the beginning, that the shadow/lighting conditions don't change at that point.

  • Surface. The robot requires a surface that has very uniform brightness. Blank white paper will work well, or any surface that is a uniform solid color with no pattern. A wood floor with a wood grain pattern, or a tile floor with texture will not work well, because the light reflection will vary as the robot moves.

  • Initial Balance. Since the color sensor cannot tell which way is up, the robot must start perfectly balanced to begin with, and then the program will try to maintain that balance position by trying to seek out the same reflected light reading that the color sensor had at the beginning of the program. Specifically, the robot must be physically balanced, which is not the same as holding it visually straight up. If you just hold it upright with your hand, it will not be physically balanced.

At the beginning of the program, the program will beep three times over three seconds, to give you time to get the robot balanced with your hands, then it measures the position at the 4th (higher tone) beep, so the goal is to have it perfectly balanced at the 4th beep. Then it starts to try to stay balanced automatically. Note that if you start the robot very close to but not quite balanced, it will drive forward or backward in the direction that it was leaning at the start. Getting a good start may require some practice, so be patient!

A good way to start the robot balanced is to start the program, then during the three beeps, support the robot only by the top of the driver's head (ultrasonic sensor) very lightly using one finger and thumb with an open gap, trying to keep the robot from leaning to either side very much at all.

The Programs

Two programs are provided for the NXT Segway with Rider, Segway and SegwayBT. Both of these programs balance the robot using a form of 'PID Controller'. See this Wikipedia article on PID Control for technical information on how a PID controller works.

The Segway program will make the robot automatically balance itself, based on its initial position, without any leaning movement by the rider. When using this program, you can lock the rider in place to keep him upright as explained below.

The SegwayBT program adds Bluetooth remote control to allow you to control the forward and backward lean of the rider from another NXT brick via Bluetooth. First, establish a Bluetooth connection from the second NXT (the remote control) to the Segway NXT on Connection 1, then run the SegwayRemote program on the remote control NXT and the SegwayBT program on the Segway NXT, starting with the Segway balanced. Now pressing the gray Left and Right arrow buttons on the remote control NXT will cause the rider to lean slightly in that direction. Use only slight movements (e.g. one or two presses in each direction), so that the Segway can keep up with the motion.

Locking the Rider in Place

When using the Segway program, which does not do any rider leaning, you can lock in the rider in place as shown below to make the robot easier to work with. Remember to remove the lock when using the SegwayBT program.

You can use either of these axles to hold the rider in place. The size 5 axle will look better, but the size 8 axle with stop is easier to insert and remove.

Challenges
  • The Segway and SegwayBT programs use a 'PID Controller' strategy to balance the robot. This type of control strategy can be used in several other applications of robotics. The article A PID Controller For Lego Mindstorms Robots provides a good introduction to PID control, as applied to line following with an NXT robot, by developing it and comparing it to simpler methods. Can you adapt the Segway program to re-use the PID strategy for another application such as line following?

  • The SegwayBT program does not modify the power to the wheels to make the robot go forward and backward. Rather, it simply leans the driver's body, which forces the robot to adjust to stay balanced, which has the effect of causing the robot to move forward and backward (somewhat like a real Segway getting started). Can you modify the control program to modify the motor power instead of the driver lean to achieve forward/backward movement?

  • The solid axle between the wheels is not necessary, but it prevents the robot from wandering sideways as it adjusts its balance. Try removing the center connection. Now can you imagine modifying the SegwayBT program to adjust the motor power to the wheels to make the robot turn left and right by remote control, while remaining balanced?

  • The Segway program is a basic PID controller that uses the color sensor's reading to determine an 'error' in its position and then tries to correct for it. If the robot starts not quite balanced, it will drive steadily in one direction, or perhaps even accelerate in that direction and then fall. The Segway program does not consider the robot's forward/backward position when determining the 'error' for the PID controller. Can you imagine modifying the error calculation to use the rotation sensor of one of the drive motors to add an error factor that increases as the robot wanders away from its starting point? Can the controller use this to keep the robot close to its starting point instead of wandering away? Will this affect its ability to stay balanced?

'Segway' is a registered trademark of Segway, Inc.


Copyright
© 2007-2011 by Dave Parker. All rights reserved.
All project designs, images, and programs are protected by copyright. Please see the usage policy.

The following are examples of programming challenges for LEGO MINDSTORMS NXT Software (NXT-G).

Move Forward, Wait, Move Reverse

You will need an NXT car with two motors. Attach one motor to Port A and the other motor to Port C.

  1. Write a program exactly like the one above. Make sure to change both Move blocks to Ports A and C. Set the Duration of each Move block to 2 seconds. The second Move block should have the Direction set to Reverse.
  2. Run the program, and observe the behavior of the NXT car.
  3. Change the amount of time that your car moves forward and backward.
  4. Run the changed program and again, note the behavior of the NXT car. Did the differences in the NXT car’s behavior the second time reflect your changes?

Extra challenge

Draw an NXT brick and label the following parts:

  • Input Ports
  • Output Ports
  • Enter Button
  • Left Button
  • Right Button
  • Back Button
  • USB Port

Wait for Touch

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move block to Ports A and C. Set the Duration of the Move block to 2 seconds. The Wait block should be set to wait for the touch sensor to be pressed.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Change the Wait block to wait for the touch sensor to be bumped (pressed and released once).
  4. Run the changed program and again, note the behavior of the NXT car. Did the differences in the NXT car’s behavior the second time reflect your changes?

Extra challenge

Add a second Wait block just after the first Wait block and before the Move block. Set one Wait block to wait until the touch sensor is pressed, and set the second Wait block to wait until the touch sensor is released. When you run this program, how does the NXT car’s behavior compare to the behavior of the car in step 4, above? Compare the efficiency of the code – which do you find easier to make in NXT-G?

Loop

Public domain wpa poster page 4. You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move block to Ports A and C. Set the Duration of the Move block to 2 seconds. The Wait block should be set to wait for the touch sensor to be pressed. The loop should continue forever.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Press the touch sensor again, and observe the behavior of the NXT car. How many times do you think the car will perform this same behavior when the touch sensor is pressed?
  4. Run the changed program and again, note the behavior of the NXT car. Did the differences in the NXT car’s behavior the second time reflect your changes?

Extra challenge

Make the car continue to drive forward each time the touch sensor is pressed until the touch sensor has been pressed four times in total. Hint: Change the settings of the Loop block. Set the Control to Count, and change the count number.

Change direction with Touch Sensor

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move blocks to Ports A and C. Set the Duration of both Move blocks to Unlimited. The second Move block should have the direction reversed. The Wait blocks should be set to wait for the touch sensor to be pressed. The loop should continue forever.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Press the touch sensor again, and observe the behavior of the NXT car. What has changed?
  4. Keep the program running, and continue to press the touch sensor multiple times. You have made the touch sensor into a toggle switch for the direction of the motors of your car!

How To Program An Nxt Segway Labviewlasopafs Charger

How

Extra challenge

Change the direction of each Move block so that at least one Move block causes the car to turn. Now you can control which way the motors turn by pressing a single touch sensor! What are the limitations of this program? What would you like to change about the program?

How To Program An Nxt Segway Labviewlasopafs Hoverboard

Light Sensor: Stop a black line

You will need an NXT car with two motors, a light sensor, and black electrical tape. Attach one motor to Port A and the other motor to Port C. Attach the light sensor to Port 3.

  1. Write a program exactly like the one above. Make sure to change the Move blocks to Ports A and C. Set the Duration of both Move blocks to 2 seconds. The second Move block should have the direction reversed. The Wait blocks should be set to wait for the touch sensor to be pressed. The loop should continue forever.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Press the touch sensor again, and observe the behavior of the NXT car. What has changed?
  4. Keep the program running, and continue to press the touch sensor multiple times. You have made the touch sensor into a toggle switch for the direction of the motors of your car!
How to program an nxt segway labviewlasopafs battery

Extra challenge

Change the direction of each Move block so that at least one Move block causes the car to turn. Now you can control which way the motors turn by pressing a single touch sensor! What are the limitations of this program? What would you like to change about the program?

Switch

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move blocks to Ports A and C. Set the Duration of all Move blocks to 2 seconds. Notice the directions of the Move blocks – the first is forward, the top block in the switch is all the way to the left, and the bottom block in the switch is all the way to the right. The Switch should be set to be controlled by the touch sensor being pressed.
  2. Add a loop to the program so that it repeats. Hint: put the loop where the program will let you keep using the touch sensor to control the motors. Add a beep so that you know when the cycle begins again.
  3. Run the new program and experiment with steering the NXT car this way. What are the program’s limitations? What would you change about this program?

Extra challenge

Pretend your motor is a generator. Program the generator to turn on when the lights in the room go off, and to turn off when the lighs in the room come back on. The program should be able to perform these tasks repeatedly. Hint: Use one or more loops!

Task split

You will need an NXT brick.

  1. Write a program exactly like the one above. Note that the sequence beam has been split into two sections. The Sound block is set to play a sound file – pick any one you like. Make sure the check box next to ‘Wait For Completion’ is checked so that the sound plays until the whole file has finished. Set the Display block to display an image – choose any one you like. Set the Wait block to wait for an amount of time, such as 3 seconds. This Wait block allows the image displayed to continue to be on the screen for some time. Without it, the image would show up so briefly that you probably would not be able to see it!
  2. Run the program and notice how both actions can be performed by the NXT brick at once.
  3. Change the program to perform three tasks at once by adding another arm to the sequence beam. This can be anything you like – you can add a sensor and control it, or add motors and control them, for example.
  4. Run the new program and notice that all three tasks can be performed at once!

Extra challenge

Think about building something other than a car that could do two things at the same time and would need a split task. What would you build and what would it do?

The following two tabs change content below.
The Tufts Center for Engineering Education and Outreach (CEEO) in Boston, Massachusetts, is dedicated to improving engineering education in the classroom, from Kindergarten to college. The Center houses faculty, staff, and graduate students from engineering disciplines and the education department.
  • Chair for Mr Bear - 21 August 2020
  • Assistive Technology: Making Lives Easier - 20 August 2020
  • Sturdy Tower - 14 June 2020

Related Posts