How To Program An Nxt Segway Sensor

How To Program An Nxt Segway Sensor Average ratng: 5,6/10 8222 votes
  1. How To Program An Nxt Segway Sensor Replacement
  2. Help

Hey guys, we are students from germany and we must program a Balancing NXT SEGWAY with a Hitechnic Gyro Sensor. We want to test the Sample File Self Balancing Robot Code under. Robotics Academy ROBOTC for MINDSTORMS Sample Programs NXT Miscellaneous Self Balancing Robot.c (CODE below).

These examples (ZIP) demonstrate a range of techniques for working with motors in NXT-G.

Drive for time

  • This code turns on Motor A for two seconds, and then turns it off. Similar code can be made by adding motors or changing times.

Drive to black line

  • There are many ways to stop a car at a black line. Using a light sensor attached to Port 1, the program takes the initial light reading, drives forward (one motor car) and waits for a difference greater than or equal to 5. Once this difference is reached, the Switch stops the NXT and exits the program.

Line follower: Switch

  • This program is works like the Line Follower: Wait for Dark program but it uses a Switch. The program runs a Switch–in a infinite Loop–that runs Motor A and makes sounds when reading light. The program stops Motor A then runs Motor C for 0.25 seconds when reading dark.

How To Program An Nxt Segway Sensor Replacement

Line follower: Wait for dark

  • This program runs Motor A until the light reading is less than 50. Once the light reading is less than 50, Motor A stops and Motor C runs for 0.25 seconds. This processed is infinitely looped.

Lurch 1

  • This code uses a Loop to turn Motor A on-and-off three times. When downloaded to a single motor car, this program will accelerate the vehicle forward in three short bursts. The number of loops can be changed by modifying the Count of “3”. Alternatively, if you want an infinite program, you can set the Control of the Loop to Forever.
How

Lurch 2

  • This program beeps, runs Lurch-1, then beeps again.

Proportional control for position

  • If a car is programmed to travel 12?, how do we know is actually traveled that distance? Often, the cars momentum will carry it past the desired location even though the motors have stopped running. The solution to this problem is a proportional control loop. By continually monitoring the distance from the desired location, the motor speed can be slowed as the car approaches. The governing formula is defined as P*(desired-current) where P is an arbitrary constant.In this program, a desired location is set at 50 degrees of the rotation sensor. This value is continually subtracted by the current rotation traveled. The difference is multiplied by two and this becomes the value of the “power” variable. The Compare Block determines the direction Motor C will travel: forward if “power” is positive, backward if “power” is negative. Thus, when the car first starts off, its current position is zero and its desired position is 50. Therefore, the power setting used is 100, which is full power forward. If the car overshoots its mark, the power setting will become negative and the car will travel in reverse. The goal of proportional control is to find a constant that will get the system to equilibrium in the shortest time with the least amount overshoot and the most accuracy.

Advanced proportional control

  • The advanced proportional control program works the same way as the basic version; however, this code allows the user to vary the proportionality constant. When run, the NXT first displays the current proportionality constant that the later “power” variable will be divided by. Thus, if 4 is shown on the NXT, the proportionality constant will be ? or .25. The constant can be changed by turning the rotation sensor. Only positive values will work. After the constant is set, a press of the touch sensor will “Switch” into the proportional control loop from the basic program. Experiment with different constants. Note the difference between very small constants and very large constants.

Random motion

  • The code will run Motor A in a random direction (via a Random-Comparison Block combination), at a random speed, for a random amount of time. The motor speeds will fall between 0-100 and the time will fall between 0-3 seconds.

Snake

Help

  • When run, this code will cause a car to “snake” forward in wide arcs. The length of the turns can be modified by changing either the time or motor power.

Touch sensor fork

  • This code uses two very important coding commands, Switches and Loops. The touch sensor Switch causes Motor A to go forward if the touch sensor is released and backward if it is pressed. The Loop causes the Switch to loop infinitely.

Wait for push

  • This code illustrates the Wait-for-Push command. When a touch sensor on Port 1 is pressed, Motor A will stop.
Sensor

Wait for stall

  • This code runs motors B and C until they stall. The code takes two rotation sensor readings, with a very short delay in between them. The loop exits when the difference between the two readings becomes less than a certain threshold. So if a motor slows down because it encounters an obstacle, the code will stop running the motors. A short delay in the beginning is necessary so that the motor can start moving before the rotation sensors start taking readings. Note that if the speed of the motor is decreased, the threshold for the difference needs to be lowered as well. This program was adapted from Brian Davis’ code.

Resources

  • NXT-G examples – motors (ZIP)
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.
How to program an nxt segway sensors
  • GPS accuracy testing with LEGO bricks - 10 September 2015
  • Iteration, collaboration, and documentation - 23 July 2015
  • Energy losses - 23 July 2015

Related Posts

Using the Light Sensor

To learn to use the light sensor and to monitor the light sensor using the Front Panel on LabView.
Final Program
Figure : The final block diagram to display the intensity and switch on/off the light on the sensor.
Figure : Front Panel showing the switch for the light and the intensity display.

Contents

Light sensor block

The light sensor block is a part of the input blocks in the NXT Toolkit. You can insert a light sensor block by opening the Functions Palette -> Addons -> NXT Toolkit -> NXT Library -> Input. Note that the input terminal says that the Port should be Port 3.
Figure : Light Sensor block in the NXT Toolkit on LabView.
Figure: Light Sensor terminals

Converting number to strings

To display the intensity on the display of the brick, it needs to be in the string format, whereas the light sensor gives the intensity in a number format. To convert a number to string, we use the Number to String conversion block.

Writing the program

Close existing VI's and open a new VI from the Getting Started window. Insert a while loop, and into this, insert a Light Sensor block and a Display Text block. Insert a Number to String conversion block and wire it to the Text terminal on the Display Text block. Wire the Intensity terminal on the Light Sensor block to the number terminal on the Number to String conversion block.

Inserting Control and Indicator

To control the Light sensor and to indicate the intensity on the Front Panel, we need to include two blocks which will do these tasks. To do this, on the Generate Light terminal of the Light Sensor block, right click and select Create-> Control in the dropdown menu to insert a Floodlight box. You will see that this will insert a switch on the Front Panel.
To display the intensity on the Front Panel, we need to insert a Intensity Indicator. To do this, move the cursor near the wire between Intensity terminal and the Number to String conversion block until you see a wire spool cursor. Now right click and Create-> Indicator to insert the Intensity Indicatior.
Once this is done, the program is almost done, and you need to download the firmware on to the brick. While downloading the firmware keep the cable connected and choose Debug on the NXT Terminal.
Figure : Typical Intensity display on the Front Panel
You will be able to see the intensity real time on the Front Panel. Lookup the Chapter 2 and the last section to replace your Intensity display on the Front Panel with a chart.
Posted on