Upload program from the nxt robot ultrasonic sensor


One rotation is equal to degrees, so if you set a motor to turn degrees, its output shaft will make half a turn. The built-in Rotation Sensor in each motor also lets you set different speeds for your motors [by setting different power parameters in the software]. Try running the motors at different speeds. The Ultrasonic Sensor enables your robot to see and detect objects. You can also use it to make your robot avoid obstacles, sense and measure distance, and detect movement.

The Ultrasonic Sensor measures distance in centimeters and in inches. The Ultrasonic Sensor uses the same scientific principle as bats: Large sized objects with hard surfaces return the best readings. Assignment Goals In this assignment, you will learn how to do basic real-time programming on an embedded device with a runtime that supports real-time tasking.

Working in Groups Solve this assignment in your groups. Report Hand-in The report must consist of the following: Listings of well commented and well structured programs for the Part2, Part3 and Part4 Ada projects , General descriptions of your solutions and how your code is supposed to work and why, Answers to all parts of this assignment.

Make sure that the package still contains the NXT unit, all sensors light sensor, 2x touch sensors, sound sensor, distance sensor , all three motors and all the cables. Please also flash the original firmware back into the brick right after you finish the demonstration, TA will help you in that. Demonstration The last part of this assignment consists of building a robot car that can follow a car on a track see below. Our Ada programs for NXT will contain following parts: The Ada main procedure file, e.

Image started at 0xc Now you can disconnect the robot and try testing it. Ada drivers for NXT, originally located in C: Program Skeleton Create a helloworld.

Background; end helloworld; Note that we assigned lowest priority to this procedure by using attribute 'First which indicates the first value of a range. Next, we need to define the Tasks pacakge in tasks. Your code should do the following: Consult the examples and the drivers package to get more information about API usages.

Handling Events Ideally events generated by external sources are detected by the interrupt service routines ISRs. First we need to create a protected object named "Event" with single entry as: For example, a task can block on receiving event: Now create a new task "MotorcontrolTask" that does the following in an infinite loop: Wait for event "TouchOnEvent" Make the car move forward by activating the motors Wait for event "TouchOffEvent" Make the car stop As suggested by the names of the events, the idea is that they should occur as soon as the user presses and releases the attached touch sensor.

Extending The Program Attach a light sensor to your car that is attached somewhere in front of the wheel axis, close to the ground, pointing downwards. The job of EventdispatcherTask is just to create the events signaling button and light behavior, independent from each other. All "logic" should happen in MotorcontrolTask, i. The task must not read the sensors by itself nor communicate with EventdispatcherTask by other means than the event protected object, i.

A frequent mistake is that the periodic EventdispatcherTask generates an event each time it is executed, reporting the current state of the sensors. Instead, it should only generate events at state changes: The same for the light sensor: When the table edge is detected, generate one event.

Don't "spam" the event system with redundant information. Of course, when the touch sensor is pressed again, a new event needs to be generated.

What To Hand In Please hand in only the source of the full second program that includes the light sensor code. Periodic Tasks The structure of the system in this part is as follows: We have three tasks that are scheduled periodically, with different periods: A task "MotorcontrolTask" that only takes care of controlling the motors and receives commands from the other tasks.

A task "ButtonpressTask" that senses the state of the buttons and sends commands to MotorcontrolTask. A task "DisplayTask" that displays some interesting information about what is going on currently. Note that there is no task sensing the distance yet. This will come later. Basic Periodic Schedule Before we implement the actual tasks, we need a way for them to communicate. Using this, we will now define the tasks in our system: Define a task "MotorcontrolTask" that "executes" the "driving command".

If driving duration is still positive, it should set the speed of the motors accordingly and decrease the driving duration by its period length. Define the task with a period of 50ms. Define a task "ButtonpressTask" that reads the touch sensor.

Further, define the task with a period of 10ms. Further, define a third task "DisplayTask" that outputs some useful information on the LCD and is periodic with period ms. Incorporating Distance Measurement Add a distance sensor that points forward to your car and connect it to a sensor port.

Further, the following hints may help: Just as the light sensor, the distance sensor needs to be initialized. Add the API code and examples. The distance sensor is not very precise. Use a book or a sheet of paper as a test object to which the car should measure the distance. This will give more stable sensor readings. You may play with the task periods in order to experiment with reaction times, but keep in mind that the distance sensor needs a certain minimum time between two sensor readings.

Readings faster than every ms have shown increasingly degraded data quality. As an appropriate speed for driving the car, the following strategy is quite elegant: This is also called a "proportional controller" or just "P controller" in control theory.

If you have some knowledge about this field and are bored, you may try to implement a full PID controller. What To Hand In Please hand in only the source of the full second program that includes the distance sensor code. In the last part you will use all the knowledge you acquired in the above parts in order to create a car that can simultaneously: Follow a line that is drawn on the floor not necessarily a straight one!

Keep distance constant about 20cm relative to another car that is driving in front of it. The car to be followed will be provided by the teaching assistant and you may assume it only moves forward and won't be too fast, but its speed may vary over time.

The procedure will be as follows: First, each team needs to demonstrate that its car can follow a vehicle that we provide in a reasonable distance. In particular, it should neither crash into it, nor let the distance increase unboundedly, nor leave the track completely. Each team has 3 tries to complete this task for a full lap on the provided track. If all 3 tries failed, the team is disqualified but may still be able to pass the lab by demonstrating a fixed and working car later.

Second, after a full lap, the provided vehicle that your car is following will disappear. From then on, we measure the time your car takes to complete another round alone. A car may not leave the track completely nor take more than 2 minutes to complete the challenge. If you fail to do none of the jobs above then you may fail the lab. The default value is 40 cm, but the next step shows you how to change this. Enter 25 as the new constant.

Now the specified distance is 25 cm. Select the constant that reads Port A. This specifies which port s the motors are connected to. Create a constant on the port connection of the Wait for Approach VI, and select Port 2, the port that the ultrasonic sensor is connected to.

Download and run your new program on the NXT Brick.