Project lab 2 - Preliminary investigations


Date: 07/05/2013
Duration of activity: 16 hours over two days
Group members participating: Ole Rasmussen and Kasper Føns

1. Goal

The goal of this session is to conduct some preliminary investigations on the feasibility of building the envisioned system described in project lab 1.

2. Plan

Our plan is to build three machines and experiment with them. We will look at if they are able to function probably and any potential problems or complications that arises underway. The three machines we will try to build are:
  1. One that is able to count the number of holes in a Lego beam. The BeamCounter.
  2. One that is able to figure out the length of a Lego axle. The AxleSorter.
  3. One that is able to feed the other two machines with Lego. The Feeder.

3. BeamCounter

We will try to create a BeamCounter using a conveyor belt to transport beams past a system of two light sensors. We believe the light sensors will be able to detect the number of holes in beams passing by. We begin by constructing the conveyor belt system.

3.1 Conveyor belt system

We wanted to build a conveyor belt to transport the Lego beams. Our first idea was to build the conveyor belt using Lego conveyor belt links [1], also seen on Figure 1. Using belt links would allow us to create one long conveyor belt. However, we quickly discovered that we had a very limited amount of such belt links available. They are not exactly cheap either (~$10 for 36) so we had to find another solution.

Figure 1: Conveyor Belt Links we wanted to build our conveyor system of.

Instead of using belt links, we wanted to try using Lego tank track threads, as in Figure 2. Since these tracks are of fixed length, we needed to use multiple tracks to construct a longer conveyor belt. We had to make sure that smaller beams were able to cross the conveyor belt intersections.

Figure 2: Tank Track Threads used in our conveyor belt construction.
We managed to integrate multiple tank track threads into a longer conveyor belt. The belts were interconnected with gear wheels and could be driven by only one motor. Our design can be seen in Figure 3.

Figure 3: Belt system to move Lego beams forward.
Figure 4: Rotating Lego axle helps bringing Lego beams of size three over the gap between the tank threads.
We had problems with smaller Lego beams with a length of two or three. We added rotating Lego axles between the intersections of the tank threads as can be seen in Figure 4. This helped to move beams of length three over the intersection, but length two beams could be stuck and would never move forward. The conveyor belt still needs tinkering to work properly. This will be a problem for a future lab session.

3.2 Counting beam holes

To count the beam holes we added two light sensors. One of the light sensors emits light onto the other. We count the number of holes by counting how many times the light beam is broken by a beam passing by.

Our solution can be seen in Figure 5. Using a simple program we were able to count the number of holes in a beam. If a longer period of time passes where the light beam is not broken, we interpret that as a beam has fully passed the sensors, and then we know the length of it. In rare occasions we could see that our solution would come up with a wrong hole count. We hope to fix this in a future lab by adding walls on the side of the track, only making it one beam wide. This should make sure that the beam is passing the sensor in a straight line and at a set distance from the sensors.
Figure 5: Light sensors counting the number of holes in a Lego beam by sensing if the light beam is broken.

4. AxleSorter

The AxleSorter should be able to determine the length of a given axle. A key difference from beams is that axles does not have any holes or other easily detectable characteristics for determining its length.

We had two ideas on system that should measure the axle length. The first system would use two wheels through which the axle should pass while the second would use light sensors.

4.1 Car wheel idea

The first idea was to use two wheels connected to two motors. One of the motors should always be powering the first wheel forward. When an axle would hit the wheel, the wheel should drive the axle forward but also push it against the other wheel, which should then rotate for as long as the axle was between the wheels. The second motor would then be connected in float mode to the second wheel and use the tachocounter to register how long the axle was. A prototype can be seen in Figure 6.

Figure 6: AxleSorter idea. One of the wheels should be power by a motor while the other should be connected to a motor in float mode, using the tachocounter to measure the length of the axle.
We had to ditch the two-wheel idea. We found that a single wheel was not able to pull in the axle; we had to push it pretty hard before the wheel had traction with the axle.

4.2 Light sensor idea

Our second idea was to use an LED and a light sensor and move an axle between the two, such that we could register the time it took for an axle to pass by. One could use a tilted smooth surface and let the axle glide down it, past the sensor. Our first design can be seen in Figure 7.

Figure 7: First light sensor AxleSorter design. When an axle passes by, the sensor should be able to register the the light breaking.
We added a casing around the system to make it robust against light from the environment. It can be seen in Figure 8.

Figure 8: AxleSorter now with casing to protect it from environmental lighting.
Figure 9 and 10 shows how it looks from the LED side of the system when no axle is there and when an axle is passing by.

Figure 9: AxleSorter where no axle is currently passing by. The light sensor diode is clearly visible.

Figure 10: AxleSorter where an axle is currently passing by the sensing system. Notice that the light sensor diode is not completely covered by the axle, but this was not a problem in practice.
A quick program showed that it worked reasonably well. We measured the time it took from the light beam was broken until it was unbroken again while the casing was tilted a bit (See Figure 11).

Figure 11: AxleSorter tilted. Axles can be inserted in the top right and will exit in the bottom left. The system measures the time it takes for an axle to move past the sensor, which is then translated to an axle length.
A major problem with this design is that it is very time sensitive. For example, if we had programmed that it takes 40ms for one axle length unit to pass by the sensor, changing the tilt angle or the speed of which the axles is dropped into the system would result in a wrong axle length detected. This brings us to the next iteration of our prototype.

4.3 Motor + light sensor idea

Our next iteration prototype was a mix of our two initial ideas: driving axles with a motor and sensing the time an axle uses to pass by a light sensor. We rebuilt our design so that a wheel was used to drive the axle past the light sensor at a steady rate (the rate of the motor) and it would therefore be tolerant against slope changes. We could not fit an LED into the new system, as the wheel had to be correctly placed above the light sensors and the LED was a bit too high. We could however use the old RXC light sensors. Our new system can be seen in Figure 12 and a polished version in Figure 13. As can be seen in Figure 12, an axle is passing under the wheel and is being driven forward by it. The two RCX light sensors are the two smaller blue boxes. Figure 13 shows that the motor is geared down from a z16 gearwheel to a z40 gearwheel. This is a gear ratio of 40/16 = 2.5. Since the solution is very sensitive to time, we have geared it down so that axles take longer to move through our sensors. It means there is a larger gap in time between axles of length n and n+1.

Figure 12: Refined system where an axle is currently passing through the system. Axles are driven forward by the wheel at a constant speed.
Figure 13: Polished version of our AxleSorter.
Below is the code for our AxleSorter. A specific time of TIME_PER_AXLE_LENGTH specifies how long time passes for a single axle length unit (later explained how we found it to be 301). It uses one motor for driving the wheel and two sensors, one to send out floodlight and one to sense if the light beam is broken.
It then samples the time period it takes for an axle to pass by the sensors and divide this by TIME_PER_AXLE_LENGTH to gain the axle length.

 package olefoens.axelsorter;  
   
 import lejos.nxt.LCD;  
 import lejos.nxt.NXTRegulatedMotor;  
 import lejos.nxt.addon.RCXLightSensor;  
 import lejos.util.Delay;  
   
 public class AxelSorter implements Runnable  
 {  
   private static final int LIGHT_THRESHOLD = 550;  
   private static final float TIME_PER_AXLE_LENGTH = 301;  
   
   private final NXTRegulatedMotor motor;  
   private final RCXLightSensor sensor;  
   
   private AxelListener listener;  
   
   public AxelSorter(NXTRegulatedMotor motor, RCXLightSensor floodLight,
                          RCXLightSensor sensor)  
   {  
     this.motor = motor;  
     this.sensor = sensor;  
   
     floodLight.setFloodlight(true);  
     sensor.setFloodlight(false);  
     waitForFloodLightOn();  
   }  
   
   public void setListener(AxelListener listener)  
   {  
     this.listener = listener;  
   }  
   
   private void waitForFloodLightOn()  
   {  
     LCD.drawString("Waiting for", 3, 5);  
     LCD.drawString("Floodlight ON", 2, 6);  
     while(getLightValue() < LIGHT_THRESHOLD)  
     {  
       Delay.msDelay(5);  
     }  
     LCD.clear();  
   }  
   
   private int getLightValue()  
   {  
     return sensor.getNormalizedLightValue();  
   }  
   
   @Override  
   public void run()  
   {  
     motor.forward();  
   
     LCD.drawString("Light sensed: ", 0, 5);  
     LCD.drawString("Dark: ", 0, 7);  
   
     try  
     {  
       boolean axelDetected = false;  
       long axelStartTime = 0;  
       while(true)  
       {  
         int lightValue = getLightValue();  
         LCD.drawInt(lightValue, 3, 3, 6);  
   
         if(lightValue < LIGHT_THRESHOLD && !axelDetected)  
         {  
           axelDetected = true;  
           axelStartTime = System.currentTimeMillis();  
         }  
   
         if(lightValue > LIGHT_THRESHOLD && axelDetected)  
         {  
           long axelEndTime = System.currentTimeMillis();  
           long axelTransitionTime = axelEndTime - axelStartTime;  
           LCD.drawInt((int) axelTransitionTime, 4, 6, 7);  
           axelDetected = false;  
           int length = Math.round(axelTransitionTime / TIME_PER_AXLE_LENGTH);  
           LCD.drawInt(length, 4, 11, 7);  
           listener.axelDetected(length);  
         }  
   
         Thread.sleep(5);  
       }  
     } catch(InterruptedException e)  
     {  
       motor.stop();  
       motor.flt();  
     }  
   }  
 }  
   

We found the TIME_PER_AXLE_LENGTH key parameter by running axles of different lengths through the system and recording the minimum and maximum for each axle length which defines a range for that specific axle length. For example we found that axles of length 12 would be between the sensors from 3495ms to 3614ms. We then calculated an average point inside the range, and in the example, this would be 3555ms. Dividing this number by our axle length of 12, we get 296.25, which would be the perfect TIME_PER_AXLE_LENGTH for length 12 axles.

We created a spreadsheet to see how our system would behave at different TIME_PER_AXLE_LENGTH values and calculated all the metrics described above. We ran axles of length 2, 3, 5, 6, 7, 8, 10 and 12 through the system, each between 10 and 20 times. If a given TIME_PER_AXLE_LENGTH would result in a wrong length being calculated for a given axle, the cell would be marked red in our spreadsheet. Our spreadsheet can be seen in Figure 14. We found a best-fit value of 301 and used that for our program.

Figure 14: Spreadsheet for calculating key parameter TIME_PER_AXEL_LENGTH for our AxleSorter.

We believe at this point that our AxleSorter is pretty robust, but on rare occasions it still calculates the wrong axle length. This might be tolerable, but should be looked into.

5. Feeder

The feeder machine should be able to hold both Lego axles and beams and feed the sorting machines with only one at a time at a descent rate. We found that the Feeder machine design would be worth copying from akiyuki's Axle sorter [2]. We would create a holding bay, and like [2] we would push beams and axles up using a two-step elevator. This should make sure not too many items are brought up from the bay and like [2] we could make a narrow area where only one item at a time might pass and other items would fall down in the holding tank again.

We have created the holding bay and the two-step elevator. A video of it can be seen below.


As can be seen, it elevates the items up without bringing too many items at a time. We still need to construct a conveyor belt at the top and somehow divide beams and axles apart. We also need to make sure that only one piece a time is sent on to the sorting machines.

Our elevator system is not very robust and should be redone. Sometimes the elevator gets stuck, stalling the motor. When starting the machine, we also need some way to move the elevator down to the initial position.

Having constructed this small part of the machine, we can estimate that it will take a lot longer to build a robust Feeder. We need to:
  • Redo the elevator.
  • Separate beams from axles.
  • Somehow make sure beams are laying correctly, the BeamCounter cannot sense how many holes there are if the holes are pointing upwards.
  • Only move one piece forward at a time. For example, having two item sent on just after each other, would not allow for our BeamCounter or AxleSorter to distinguish them as two separate bricks.
Because we estimate that it will take considerable time constructing a Feeder that would solve the above problems in a robust manner, we have chosen to down-prioritize it. As a solution, a human can be used to feed the system. Also, it makes little sense having a robust feeder if the rest of the system is not working properly.

6. Conclusion

We have constructed three prototypes
  • A BeamCounter that works reasonable well, but cannot transport beams of length two.
  • A AxleSorter that is nearly complete.
  • A Feeder prototype that is not nearlycomplete.

7. Next lab

We need to look at the distributor, the subsystem that should move the sorted Lego bricks into some storage unit. We also need to alter the BeamCounter so that it works more robustly.

8. References

[1] “LEGO Education | Products > Elementary > Conveyor Belt Links.” [Online]. Available: http://www.legoeducation.us/product/details/907. [Accessed: 05-Jun-2013].
[2] “LEGO Axle Sorter AS-L40A - YouTube.” [Online]. Available: http://www.youtube.com/watch?v=fM9qGZCc4DY. [Accessed: 05-Jun-2013].
Posted on 9:40 AM | Categories:

Project lab 1 - Project introduction

Date: 03/05/2013
Duration of activity: 10:00-18:00 --> 8 hours
Group members participating: Ole Rasmussen and Kasper Føns

1. Goal

The goal of this activity is to write a blog post (this one) that will describe the idea behind our end course project. The aim is to establish a foundation for understanding the rest of our project work.

2. Plan

This lab report contains the following sections:
  • Project overview
  • Project description
  • System architecture
  • Challenges
  • Related work
In the project overview, we will describe the form of the course (and project). The project description contains an introduction to and description of the requirements for the concrete project we will be working on. In the architecture section, we will describe the high-level architecture of our proposed system. The challenges section describes the areas we believe may be troublesome. In the related work section, we describe existing work that is related to ours. This may be useful for use as reference or inspiration in the project.

3. Project overview

The work that is being reported on here and in the following blog posts is the result of an end course project carried out in the 10 ECTS semester course Embedded Systems - Embodied Agents at Aarhus University. 
The course description [1] mentions that the prerequisite for examination participation is a project. According to the course homepage [2, 3] this self-chosen project is to be carried out at the end of the course, and lab reports should be written for each activity carried out. What you are currently reading is the first of several lab reports for our project.

Our concrete project is carried out in the last quarter of the course. In practice this is the period spanning the interval 03/05/2013 - 27/06/2013. While 27/06/2013 is the deadline for hand-in of the report (blog posts), the physical Lego system must be finished at 13/06/2013 where it is to be presented to the lecturer. This means we have the first 6 weeks for designing, building and coding the system while the last two weeks are used for writing and polishing the lab reports.

4. Project description

The project we have chosen is a Lego sorting system. We have defined the following requirements for the system:
  1. It should sort at least two types of Lego pieces: axles and beams (see Figure 1).
  2. It should be easily extensible.
  3. It should be completely decentralized, only running on NXT bricks with no PCs involved.
Figure 1: The two types of Lego pieces that our system should be able to sort. Axles (left) and beams (right).
The first requirement is a result of the time constraints on the project. As mentioned in the project overview section we only have 6 weeks to build the system. Thus, we decided to limit the scope of the system to only sorting two types of Lego pieces. The specific types of Lego pieces are chosen based on a reasonable belief that we can sort these pieces. Axles and beams, being as universal and known as they are, seems like some of the easier pieces to sort.

The second requirement may seem awkward. Why build an extensible system when it will only be sorting two types of Lego pieces? The reason is independent developability. By architecting the system so that it is easy to add new sorting functionality we are, by the definition of extensibility, also making the system independent developable. A result we are able to develop the different components of the system in parallel and integrate them later.

The last requirement enforces certain restrictions on the system architecture. Specifically we want the system to be deployable and usable in scenarios where there are not any PC's around. One does not want to connect and configure a PC just to sort a few Lego pieces. This requirement also has an impact on the design of the system. For example, it is practically impossible to use processing-intensive technologies like image analysis and recognition in a decentralized system - NXTs alone just are not capable of holding or processing the amount of data required. Therefore, to incorporate such technologies one or more PCs are usually included as the data processor(s) as is done in e.g. [4] and [5].

5. System architecture

We imagine the sorting system will consist of three modules: a feeder, a number of sorters and a distributor (see Figure 2). The feeder takes any (supported) Lego pieces and feeds (distributes) them to the correct sorter. The sorter takes Lego pieces of a specific type (axles, beams, pins etc.) and will be able to tell the difference between these pieces. The distributor will place the pieces in their respective buckets depending on the information it gets from the sorters.

Figure 2: The envisioned architecture of the Lego sorter consists of three modules; a feeder, a distributor and a number of sorters.

5.1 Hardware

Due to the extensibility requirement for the system it will probably be the easiest to have a separate NXT for each (sub)module. Thus, one NXT is required for the distributor and each sorter must have its own NXT. Bearing the project scope in mind this brings the minimum number of NXTs needed to four. Additionally there will also be one or more NXTs needed to control the transportation mechanism between the modules.

With regards to sensors and actuators what is needed is entirely dependent on the specific implementation of each module. For example, a beam sorter module may use a motor to transport the beams past a light sensor that counts the number of holes. Generally, we imagine that each sorter will need at least one motor and one sensor. The distributor module may need several due to its complexity.

6. Challenges

We believe there are challenges both in the physical design, construction and coding of the system. Due to its complexity, it requires a substantial effort to design and build a system that will not only work but also be fast enough to be useful (i.e. sorting one axle per minute is useless). It also requires lots of time and skill to build a complete and working sorting system since it consists of many of different parts that must be interconnected.

7. Related work

In the world of Lego constructions there is one person who everyone talks about; akiyuki [6]. This guy has built some of the most advanced Lego machines in the world, including the infamous great ball contraption [7]. His repertoire includes two Lego sorting machines; the axle sorter [8] and the vision guided brick sorter [9].

Akiyuki's axle sorter runs on a single motor and sorts Lego axles using only mechanics. No sensors or PC's are involved. We imagine we will use his machine for inspiration in building our own, especially with regards to the "feeder" part which has the responsibility of feeding the sorting mechanism with a single Lego piece at a time.

The vision-guided sorter is in a whole other league. Apart from being very slow, it also requires an external PC and web camera to run the image recognition. This is very different from our system, but we mention it here anyway since it's a fine example of what a system much more advanced than ours runs and looks like. 

8. Next lab

In the next lab we will start the project by doing preliminary investigations on the design and architecture of our system. We will do this by building prototypes of parts of the system to gauge the effort and time required. Hopefully we will gain insight into the challenges that lie ahead and can use this knowledge in the weeks to come.

9. References

[1] “Embedded Systems - Embodied Agents, Digital Control in a Physical World (Q1+2) - Search Course,” AU Course Catalogue. [Online]. Available: http://kursuskatalog.au.dk/en/coursecatalog/Course/show/26923/. [Accessed: 04-Jun-2013]
[2] “Embedded Systems - Embodied Agents, End Course Project.” [Online]. Available: http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson11.dir/Lesson.html. [Accessed: 04-Jun-2013]
[3] “Embedded Systems - Embodied Agents (DigitalControl) 2013 - End Course Project.” [Online]. Available: https://services.brics.dk/java/courseadmin/DigitalControl/pages/End+Course+Project. [Accessed: 04-Jun-2013]
[4] T.-H. Lee, “Real-Time Face Detection and Recognition on LEGO Mindstorms NXT Robot,” in Advances in Biometrics, vol. 4642, S.-W. Lee and S. Li, Eds. Springer Berlin Heidelberg, 2007, pp. 1006–1015
[5] A. C. Parietti Filho and M. B. R. Vallim, “Recognition and Separation of Objects on a Lego Mindstorms NXT Conveyor Belt Using Log-Polar Transform and Artificial Neural Networks,” in Robotics Symposium and Latin American Robotics Symposium (SBR-LARS), 2012 Brazilian, 2012, pp. 290–295.
[6] “LEGO TECHNIC - Akiyuki blog,” 17-Jun-2013. [Online]. Available: http://legokarakuri.blog91.fc2.com/. [Accessed: 17-Jun-2013]
[7] “LEGO Great Ball Contraption (GBC) Layout 2012.9 - YouTube,” 17-Jun-2013. [Online]. Available: http://www.youtube.com/watch?feature=player_embedded&v=sUtS52lqL5w. [Accessed: 17-Jun-2013]
[8] “LEGO Axle Sorter AS-L40A - YouTube.” [Online]. Available: http://www.youtube.com/watch?v=fM9qGZCc4DY. [Accessed: 17-Jun-2013]
[9] “LEGO Mindstorms NXT Vision Guided Brick Sorter ver1 - YouTube.” [Online]. Available: http://www.youtube.com/watch?v=6lZ9rSZwDzE. [Accessed: 17-Jun-2013]
Posted on 11:25 AM | Categories:

Week 12 - Endcourse Projects



In this lab session we will describe three end course projects and choose one of them for completion.

Duration of activity: 7 hours
Group members participating: Ole Rasmussen, Kasper Føns


Goal

Discuss and settle on an endcourse project.

Plan

First we will briefly sketch each endcourse project idea, and then give a more detailed view of each project in succession.
  1. End course project overviews
  2. Project details - Lego Sorting
  3. Project details - P2P Bluetooth Mobile Ad-hoc Network
  4. Project details - LegWay Alishan Train Track
  5. Chosen project

1. Project overviews

We have three ideas to an endcourse project:
  • Lego Sorting machineMachine that is able to sort some types of Lego Bricks automatically. We believe we can sort the items seen in Figure 1.
  • P2P Bluetooth Mobile Ad-hoc NetworkBluetooth communication module enable many NXT bricks to communicate together. Built using the Destination Sequenced Distance Vector routing protocol.
  • LegWay Alishan Train TrackBuild a LegWay robot which is able to traverse the Alishan Train Track.

2. Project details - Lego Sorting

Figure 1: The different types of axles and beams that the Lego sorter must be able to sort
We have the following requirements for the sorting system:
  • It should be easily extensible allowing new sorting modules to be built and integrated into the existing architecture
  • It should sort at least two types of Lego pieces: axles and beams (figure 1)
  • It should be completely decentralized, only running on NXT bricks with no PCs involved
We imagine the system will be split in three modules: a separator, a number of sorters and a distributor (figure 2). The separator takes any (supported) Lego piece and distributes it to the correct sorter. The sorter takes Lego pieces of a specific type (axles, beams, pins etc) and will be able to sort these pieces. The distributor will place the pieces in their respective buckets depending on the information it gets from the sorters

We will not be making the separator module in this project so the actual system will only contain the distributor and sorters. As a result, the Lego pieces must be sorted into groups before they can be used with the system.
Figure 2: The envisioned architecture of the Lego sorter consists of three modules: a distributor, a number of sorters and a separator

3.1 Platform

Each module requires its own NXT. Furthermore, a separate NXT will be required for each sorter. This brings the minimum number of NXTs needed to four. There will also be one or more NXTs needed to control the transportation mechanisms between the modules.

With regards to sensors and actuators what is needed is entirely dependent on the specific implementation of each module. For example, a beam sorter module may use a motor to transport the beams past a light sensor that counts the number of holes. Generally, we imagine that each sorter will need at least one motor and one sensor. The distributor module may need several due to its potential complexity.

3.2 Architecture

The distributor module will probably be a closed-loop [1] PID [2] controlled car-like thing driving around on a track.

The sorters will use appropriate NXT sensors (light, ultrasonic etc.). Each sorter will probably be an open-loop [1] system due to their inherent simplicity (though complex in construction).

3.3 Challenges

We believe the primary challenge is the physical design and construction of the system. Due to its complexity, it requires a substantial effort to design and build a system that will not only work but also be fast enough to be useful (i.e. sorting one axle per minute is useless).

The secondary challenges lie in the architecture and implementation of the distributor module. This module is the most advanced as it needs to be able to put any (supported) Lego piece, coming in any order, from any sorter, in the right bucket as fast as possible.

3.4 Presentation goal

We plan to present a working system that can efficiently sort Lego axles and beams.

3. Project details - P2P Bluetooth Mobile ad-hoc Network

This project is about building a robust and scalable communication medium that NXTs can use to communicate with eachother. There are a number of requirements:

  • Should use Bluetooth for communication
  • Should only use NXTs. There should be central component, like a computer.
  • Should be able to scale to at least 30+ peers
  • Should be reasonably fast

3.1 Platform

We need to use multiple NXTs hardware units each functioning as a peer in the Mobile Ad-hoc Network. We are required to build a software module and build routing tables inside each NXT and use this for forwarding messages trough the network. It should independent enough so that it can be used as an API for communication.

3.2 Architecture

Our envisioned software architecture can be seen in Figure 2.
Figure 2 - Envisioned software architecture for our Mobile Ad-hoc Network routing system.
A Client registers a RouterListener which then receives messages from the Router.

3.3 Challenges

There are many challenges in this project:
  • Maintaining routing tables is not easy. NXT's can suddenly disappear (battery, out of range) and can suddenly appear (in range, just powered up). These updates needs to be propagated trough the network so that packages can be routed correctly.
  • To allow reliable communication, some sort of TCP-like acknowledgement must be sent.
  • Bluetooth devices have a limited number of connections it can maintain

3.4 Presentation goal

For this project we would like to start up 10 NXT's. These should start building a routing table and then we would like to show that one NXT can send a message to another NXT where it have to route it trough multiple peers. We would see that the message ends up at the NXT in the other end of the routing path. Then we would rearrange how the NXTs are placed, and then show that it is still possible to send a message through the network and see that it takes a different path.

We would also like to setup a special peer (a computer) where all the NXT's sends their full routing tables once a while. This way, we can draw a graph with the current routing table for all the devices.

4. Project details - LegWay Alishan Train Track

We want to create a LegWay which can traverse the Alishan Train Track.

4.1 Platform

We will only need one NXT with two motors and some sensors for making sure that we are standing upright. Sensors would probably be gyroscope, tachocounters and lightsensors.

4.2 Architecture

We believe this can be built using a behavioral model [3]. The highest priority behavior would be to make sure we maintain balance. The lower behavior will make sure we are following the track while the lowest behavior will make us move forward.

4.3 Challenges

The main challenge is to maintain the balance when beginning to climb or descend on the Alishan train track. The balance point will move forward when climbing and backwards when descending.

4.4 Presentation goal

Here we will present the robot which should hopefully be able to climb the Alishan train track. If it is not able to do that, we will show that it is able to drive up a hill and down again.

5. Chosen project

The first project we wanted to make our endcourse project was the P2P Bluetooh Mobile Ad-hoc Netwprk project. However, we made small tests that showed that it would be very cumbersome to create such a network because of:
  • Each NXT can only have either maximum three outgoing connections OR one ingoing connection. This creates a master node in a socalled piconet with a maximum of three slaves.
  • One could create a socalled scatternet (multiple piconets where some piconet slaves disconnect from their master to connect to another piconet, thus forming a bridge between the two piconets). However, since connection estabilishing takes a matter of seconds the resulting network would not be able to scale and thus uninteresting.
Therefore we dropped this idea.

Then there is the choice between the Alishan Train Track LegWay and the Lego Sorter. We think it would be funniest to build the Lego Sorter, since it can always stand in the Lego Room and be used to sort some Lego bricks. Therefore we have chosen that idea.

References

[1] Control Theory, WikiPedia, http://en.wikipedia.org/wiki/Control_theory
[2], PID Control, chapter 5, pp. 179-190 of  Fred G. Martin, Robotic Explorations: A Hands-on Introduction to Engineering
[3], Maja J Mataric, Integration of Representation Into Goal-Driven Behavior-Based Robots
Posted on 9:53 AM | Categories:

Week 11


In this lab session we will experiment with the LeJOS behavior architecture.

Duration of activity: 7 hours
Group members participating: Ole Rasmussen, Kasper Føns

Goal

To complete the exercises for Lego Lab 10.

Plan

Since our goal is to complete the exercises for this weeks lab the plan will be to complete each exercise in sequence:
  1. BumperCar
    1. Testing what happens when the touch sensor is pressed
    2. Implement an exit behavior
    3. Investigate arbitrator
    4. Move sampling of the ultrasonic sensor to another thread
    5. Modifying DetectWall behavior to first move backwards
    6. Modifying DetectWall to allow activation while turning
  2. Implementing dynamic prioritization - Motivation functions

1. BumperCar

1.1 Touch sensor pressed, what happens?

We have installed the sample program "BumperCar" from LeJOS. We have a ultrasonic sensor in front and a touch sensor dangling that we can manually touch to simulate the robot bumping into something (Figure 1).
Figure 1 - Our robot design. Notice that only the front ultrasonic sensor is used and the
touch sensor is manually pressed.
There are three types of reactions when pressing the touch sensor:
  1. Pressing and releasing touch sensor very fast
    The robot will turn right and then go forward again. Looking into the source code of the program, this happens because the DetectWall behavior want's to take control, but when the DriveForward behavior exits the action method, DetectWall no longer want's to take control. Since the DriveForward behavior contains a bug, where it only stops the left motor when being interrupted  the robot turns left until the left motor is again told to move forward. This is fixed by stopping both right and left motors in the DriveForward behavior when interrupted.
  2. Pressing and holding the touch sensor for a while
    Here the robot will move backwards for a little while and then turn right. This happens because the DetectWall behavior has higher priority than the DriveForward behavior. The DriveForward behavior gets suppressed and the DetectWall behavior gets control. It is the one that backs off and turns.
  3. Pressing and keep holding it down
    Here the robot will keep driving backwards and turning. This happens because DetectWall always wants control and it has higher priority.

1.2 Implementing an exit behavior

Here we should implement a behavior which wants to have control when the ESCAPE button is pressed, and when its action is called, will call System.exit(). Notice that this kind of behavior is a bit strange, and really should be implemented using a listener on a Button outside of the Arbitrator class.

At the lecture we were shown that the DetectWall behavior does not respect calls to the suppress method. Therefore if the DetectWall behavior is executing its action method, then when pressing the ESCAPE button nothing will happen, since DetectWall  ignores all calls to suppress. We need to implement correct suppression handling to fix this issue.

Our implementation of the exit behavior can be seen in Figure 2.

Figure 2 - Exit behavior implementation. Wants to take control if ESCAPE is pressed,
exits the system if action is called.

We tested the implementation and it behaved as we expected. When the DriveForward is active and we quickly touch the ESCAPE button, DriveForward is stopped, but then the ExitBehavior no longer wants to take control, just as in section 1.1. This was as expected. We also expected that the DetectWall behavior would not respect the suppress method call, which we also saw in our testing.

We modified DetectWall behavior to respect the suppress method call, Figure 3 shows our final implementation which worked beautifully (i.e., it was suppressed immediately when the ESCAPE button was pressed).

Figure 3 - Implementation of DetectWall which respects call to the suppress method.

1.3 Investigate Arbitrator

We are asked to investigate if the takeControl method of DriveForward is called when DetectWall's takeControl method returns true. We will do this by examining the Arbitrator implementation.

Inside the Arbitrator there are two threads running. One is the main thread which calls the Arbitrator.start() method. This thread is responsible for calling the action() method of a behavior. The other thread is a thread inside the Arbitrator called Monitor. The monitor thread samples the takeControl method on the registered behaviors and stores what behavior should become active next. See Figure 4 for the code.

Figure 4 - The Monitor thread implementation inside the Arbitrator class.
When a higher prioritized behavior wants to take control, lower ones are not asked. 

The monitor calls the takeControl() method on each behavior starting from the highest prioritized one. As soon as a behavior returns true, the monitor stores this in a field and stops checking lower prioritized behaviors. This means that if DetectWall returns true in its takeControl() implementation, the takeControl method of the DriveForward behavior will not be called. That answers this question.

1.4 Move ultrasonic sampling to separate thread

The takeControl method is obligated to return its results as fast as possible. Since the DetectWall behavior samples the ultrasonic sensor, it must wait approximately 25msec for a ultrasonic burst to be sent and received. This is too long and in this section we will move this sampling to a new thread, the UltrasonicSampler thread. Figure 5 shows the complete DetectWall implementation with our UltrasonicSampler thread inside.

Figure 5 - DetectWall with UltrasonicSampler to avoid waiting too much in the takeControl method.
Notice that we have set the lastDistance to Integer.MAX_VALUE as a first value before the first sample is registered. Also notice that the field is declared volatile, which indicates that the value will be used by different threads. The UltrasonicSampler is set to be a daemon thread, so that the system exists correctly if the main thread stops. It works as expected, though the change can not be observed by looking at the robot running.

1.5 DetectWall to reverse a second before turning

Here we are asked to change DetectWalls action to first reverse for one second and then turn. This should be a straightforward implementation, but we need to consider that we can be suppressed doing both actions.
Our implementation can be seen in Figure 6.

Figure 6 - DetectWall action. Implements reverse for one second while still handling suppression calls.
It worked as expected. We could suppress it and it went backwards for approximately one second. Notice that we removed BumperCar.leftMotor.rotate(-180, true) since this would only make it go reverse for another 180 tacho counts.

1.6 Modify DetectWall to allow second activation while turning

This time we are asked to allow the DetectWall behavior to activate while it is turning. We will implement this by suppressing ourselves, if the touch sensor is pressed, while we are active and turning. When we suppress ourselves we exit from the action method, after which the DetectWall behavior should once again be chosen in the Arbitrator. Our implementation can be seen in Figure 7.

Figure 7 - DetectWall with reactivation
It worked as expected.

2. Implementing dynamic prioritization - Motivation functions

We have implemented the dynamic prioritization arbitrator as suggested by Thiemo Krink [1]. The algorithm is quite simple: first find the behavior with the maximum priority, and then only activate it if the priority is higher than the priority of the behavior previously selected for activation or if there's is no such previous behavior. The code for the arbitrator can be seen in Figure 8.

Figure 8 - The dynamic prioritization arbitrator
For the behaviors the only interesting change is in the DetectWall class (DriveForward has a constant priority). The basic idea of the takeControl method is to return a high(er) priority when the behavior is currently turning than otherwise. Assume DriveForward has a priority of x. Assume also that the base priority of DetectWall is x < y. When the bumper sensor is pressed the new priority z of DetectWall should be such that z > x while setting a variable 'turning' = true. Then, when the bumper sensor is pressed again and if 'turning' is true then the final priority of DetectWall becomes q where q > z. The result is that the arbitrator will ask DetectWall to supress itself to allow the higher-priority instance of DetectWall to run. The code for the DetectWall can be seen in figure 9.
Figure 9 - Dynamically prioritized DetectWall behavior

References

Posted on 2:05 PM | Categories: