Lego mindstorms nxt car instructions
However, installation in Windows is farely simple and instructions for Windows and Linux installation can be found in instruction file. The program you will write is a simple "hello world! Priority'First ; begin Tasks. Note that we assigned lowest priority to this procedure by using attribute 'First which indicates the first value of a range.
This procedure is calling a procedure background the main procedure of Tasks of package Tasks. Your code should do the following:. Light sensors are bit tricky to initialize. Try different procedures of the nxt-display package to master output in the display. For more advanced kind of display you can use the nxt-display-concurrent package from facilities.
Make sure your code compiles without error and executes as desired on the NXT brick. Try to measure light values of different surfaces light ones, dark ones, In this part, you will learn how to program event-driven schedules with NXT.
The target application will be a LEGO car that drives forward as long as you press a touch sensor and it senses a table underneath its wheels with the help of a light sensor. For this purpose, build a LEGO car that can drive on wheels. You may find inspiration in the manual included in the LEGO box. Further, connect a touch sensor using a standard sensor cable to one of the sensor inputs. Ideally events generated by external sources are detected by the interrupt service routines ISRs.
This allows to react immediately to signals from various sources. Unfortunately, most of the sensors on the NXT are working in a polling mode: They need to be asked for their state again and again, instead of getting active themselves when something interesting happens. Our workaround for this is to create a small, second task that and checks the sensors periodically about every 10ms.
If the state of the sensor changed, it generates the appropriate event for us. Integer; -- Event data declaration Signalled: This protect object can be used by different tasks to communicate between them. For example, a task can block on receiving event:. In order to do this, declare and implement a task "EventdispatcherTask". It should call the appropriate API function to read the touch sensor and compare it to it's old state.
A static variable may be useful for that. If the state changed, it should release the corresponding event by using signal procedure of the Event protected object. Just as in part 1, put your code in an infinite loop with a delay in the end of the loop body. 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.
In order for MotorcontrolTask to have priority over EventdispatcherTask, make sure to assign a lower priority to the latter. Otherwise, the infinite loop containing the sensor reading would just make the system completely busy and it could never react to the generated events. Add further some nice status output on the LCD.
This should complete your basic event-driven program. Compile and upload the program and try whether the car reacts to your commands. Attach a light sensor to your car that is attached somewhere in front of the wheel axis, close to the ground, pointing downwards.
Extend the program to also react to this light sensor. The car should stop not only when the touch sensor is released, but also when the light sensor detects that the car is very close to the edge of a table. You may need to play a little bit with the "Hello World!
The car should only start moving again when the car is back on the table and the touch sensor is pressed again. The edge detection should happen in EventdispatcherTask and be communicated to MotorcontrolTask via the event protected object. Use two new events for that purpose. Make sure you define and use all events properly. Further, the display should provide some useful information about the state of the car. Please hand in only the source of the full second program that includes the light sensor code.
Make sure you include brief explanations and that your source is well-commented. Note that hand-ins without meaningful comments will be directly discarded. Real-time schedulers usually schedule most of their tasks periodically.
This usually fits the applications: Sensor data needs to be read periodically and reactions in control loops are also calculated periodically and depend on a constant sampling period. Another advantage over purely event-driven scheduling is that the system becomes much more predictable, since load bursts are avoided and very sophisticated techniques exist to analyze periodic schedules.
You will learn about response-time analysis later during the course. The target application in this part will make your car keep a constant distance to some given object in front of it.
Additionally, the touch sensor is used to tell the car to move backwards a little bit in order to approach the object again. Note that this is a new program again, so for now, do not just extend the program from the event-driven assignment part.
Create a new program instead. The structure of the system in this part is as follows: We have three tasks that are scheduled periodically, with different periods:. Obviously, the tasks can have different periods, since while we would like the car to react fast to the button press, we can't optically, as humans read updated information from the display faster than in certain intervals anyway. Before we implement the actual tasks, we need a way for them to communicate.
We will use a data structure that is used by the sensing tasks to communicate their movement wishes to MotorcontrolTask. We will use this global variable to pass information about driving between tasks. Before we are done with the program, there is a potential problem to be taken care of. Do you need to protect it in any way? If so, do that. Finally, compile and run the program. So far, the behavior is not too exciting, since all the car can do is just stopping or moving backwards.
The exciting part will come next. Add a distance sensor that points forward to your car and connect it to a sensor port. Leaving the light sensor attached may help later. Using the above structure of periodic tasks, extend your program with a fourth periodic task "DistanceTask". It should have period ms and read the distance sensor value in each instance. Using the sensor reading, it should try to set the driving command to a value that would make the car drive towards a target distance of around 20cm between the cars front and the object.
This means that the car should go forward if it is to far away, and backward if it is too close. By doing so, the button press will have a higher priority. The task displaying useful information should be extended to display even more useful information. Further, the following hints may help:. When you are done, compile, upload and test your program. Make sure that the behavior is as desired: The car should try to keep a distance of 20cm.
When the button is pressed, it should drive backwards for one second, after which it should resume the distance-keeping resulting in driving closer again. Please hand in only the source of the full second program that includes the distance sensor code. Again, note that hand-ins without meaningful comments will be directly discarded. 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:.
You may use any of the techniques you learned above to define and schedule tasks, read sensors and send commands to the motors. The line tracking should be done with the light sensor. The line to be followed will have the following shape: A test track is available from Jakaria's office and during the labs in the corresponding lab rooms.
For accurate sensing you will have to recalibrate the reflection values of the track and the background before each race. The reflection value depends on the ambient lighting and the track condition. The race will most likely take place on a new track in a different room.
In order to pass the lab, all teams need to demonstrate a working car that can do both jobs accurately. This has to be demonstrated on Monday, The procedure will be as follows:.
Some issues arise every year to some of the groups. Experience tells that you should take care of the following things:. 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. Otherwise, the infinite loop containing the sensor reading would just make the system completely busy and it could never react to the generated events. Add further some nice status output on the LCD. This should complete your basic event-driven program. Compile and upload the program and try whether the car reacts to your commands.
Attach a light sensor to your car that is attached somewhere in front of the wheel axis, close to the ground, pointing downwards. Extend the program to also react to this light sensor.
The car should stop not only when the touch sensor is released, but also when the light sensor detects that the car is very close to the edge of a table. You may need to play a little bit with the "Hello World! The car should only start moving again when the car is back on the table and the touch sensor is pressed again. The edge detection should happen in EventdispatcherTask and be communicated to MotorcontrolTask via the event protected object.
Use two new events for that purpose. Make sure you define and use all events properly. Further, the display should provide some useful information about the state of the car. Please hand in only the source of the full second program that includes the light sensor code. Make sure you include brief explanations and that your source is well-commented. Note that hand-ins without meaningful comments will be directly discarded.
Real-time schedulers usually schedule most of their tasks periodically. This usually fits the applications: Sensor data needs to be read periodically and reactions in control loops are also calculated periodically and depend on a constant sampling period. Another advantage over purely event-driven scheduling is that the system becomes much more predictable, since load bursts are avoided and very sophisticated techniques exist to analyze periodic schedules.
You will learn about response-time analysis later during the course. The target application in this part will make your car keep a constant distance to some given object in front of it.
Additionally, the touch sensor is used to tell the car to move backwards a little bit in order to approach the object again. Note that this is a new program again, so for now, do not just extend the program from the event-driven assignment part. Create a new program instead. The structure of the system in this part is as follows: We have three tasks that are scheduled periodically, with different periods:.
Obviously, the tasks can have different periods, since while we would like the car to react fast to the button press, we can't optically, as humans read updated information from the display faster than in certain intervals anyway.
Before we implement the actual tasks, we need a way for them to communicate. We will use a data structure that is used by the sensing tasks to communicate their movement wishes to MotorcontrolTask. We will use this global variable to pass information about driving between tasks.
Before we are done with the program, there is a potential problem to be taken care of. Do you need to protect it in any way? If so, do that. Finally, compile and run the program. So far, the behavior is not too exciting, since all the car can do is just stopping or moving backwards. The exciting part will come next. Add a distance sensor that points forward to your car and connect it to a sensor port.
Leaving the light sensor attached may help later. Using the above structure of periodic tasks, extend your program with a fourth periodic task "DistanceTask". It should have period ms and read the distance sensor value in each instance. Using the sensor reading, it should try to set the driving command to a value that would make the car drive towards a target distance of around 20cm between the cars front and the object.
This means that the car should go forward if it is to far away, and backward if it is too close. By doing so, the button press will have a higher priority. The task displaying useful information should be extended to display even more useful information. Further, the following hints may help:. When you are done, compile, upload and test your program. Make sure that the behavior is as desired: The car should try to keep a distance of 20cm.
When the button is pressed, it should drive backwards for one second, after which it should resume the distance-keeping resulting in driving closer again. Please hand in only the source of the full second program that includes the distance sensor code.
Again, note that hand-ins without meaningful comments will be directly discarded. 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:. You may use any of the techniques you learned above to define and schedule tasks, read sensors and send commands to the motors. The line tracking should be done with the light sensor. The line to be followed will have the following shape: A test track is available from Jakaria's office and during the labs in the corresponding lab rooms.
For accurate sensing you will have to recalibrate the reflection values of the track and the background before each race. The reflection value depends on the ambient lighting and the track condition. The race will most likely take place on a new track in a different room. In order to pass the lab, all teams need to demonstrate a working car that can do both jobs accurately. This has to be demonstrated on Monday, The procedure will be as follows:.
Some issues arise every year to some of the groups. Experience tells that you should take care of the following things:. 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.