|
|
# Group 8
|
|
|
|
|
|
## Lab Notebook 5
|
|
|
|
|
|
**Date:** 12/3 - 2015
|
|
|
|
|
|
**Duration:** 6-8 hours
|
|
|
|
|
|
**Participants:**
|
|
|
|
|
|
- Frederik Jerløv
|
|
|
- Casper Christensen
|
|
|
- Mark Sejr Gottenborg
|
|
|
- Peder Detlefsen
|
|
|
|
|
|
## Goal
|
|
|
The goal is to equip our NXT Robot with different types of sensors, light, 3-color and gyro in order to test these both performance-wise and against each other while executing the exercises.[1]
|
|
|
|
|
|
## Plan
|
|
|
Our plan is to follow the exercises exactly as described, testing the the different build descriptions, with different settings and external influences
|
|
|
|
|
|
## Results
|
|
|
|
|
|
### Exercise 1
|
|
|
On our first run we did not change any of the code from `Sejway.java`, this gave us more insight in if and why the program would fail. On our first try we used a table with a uniform and reflective surface which proved not to be the best surface. On the table the robot only tried to correct a forward tilt by driving forward. However the light when it tilted back didn't provide the information to drive backwards.
|
|
|
|
|
|
In Following with the suggestions made by Phillippe Hurbain[2] we moved the robot to the floor carpeting which we consider to be a non-uniform surface. this quite interestingly gave us the opposite problem. meaning the robot now only corrected backwards but not forwards, making it tilt backwards. We tried to eliminate other sources of light by closing the blinds which helped a little making the robot balance for a short while before tilting.
|
|
|
|
|
|
Even though Phillippe Hurbain[2] said that fluorescent light would not have any effect to the infrared light sensor we tried to turn the light of in the room in order to give the robot and sensor even better conditions, but it had no effect on the performance.
|
|
|
We observed that the even though the robot now exhibited the behavior we were looking for it still were not able to balance for very long, we found that the reads did not happen fast enough for the robot to correct the behavior before it had reached the tipping point.
|
|
|
|
|
|
Up until now we had started the robot standing perfectly vertical, which were a problem as the robot is heavy in the front. We started to change the offset which made the robot balance a little longer, but the one mistake we made initially was that we calibrated the robot such that if was exactly vertical on the surface beneath it. This will not make the robot balance correctly as the center of mass of the robot is a bit in front of the wheels. To counter this the robot will have to be leaned slightly backwards until it can stand almost on its own and then do the calibration. This does give a better result but the robot is still not able to balance on its own by just running `Sejway.java` unmodified.
|
|
|
|
|
|
This might be due to our sensor not being calibrated the same as the one used when writing the test programme, and we decided to move on to making a controller that would enable us to set the parameters on the fly.
|
|
|
|
|
|
### Exercise 2
|
|
|
|
|
|
For this exercise we had to build a pc controller for the NXT that would allow us to change the PID constants while the robot was running. We used `PCcarController.java`[REFERENCE] as a starting point for our new controller `PCpidController.java`[REFERENCE] and added text fields for the constants `KP`, `KI`, `KD` and `SCALE` Furthermore, we decided that it would be useful to have the current light value and `pid_val` which is the number defining whether our NXT should drive forward or backwards. Our new PC controller have a connect button, that establishes a bluetooth connection with the NXT and a set button which writes the entered values to the output stream. Figure 1 shows how the finished PC controller looks.
|
|
|
|
|
|
![Figure 1: The PC controller with the various fields and buttons.](http://i.imgur.com/YezJHRKm.jpg)
|
|
|
|
|
|
The connect button behavior is exactly the same as in the original controller but the set button behavior is new and it writes the values from the five input fields to the `DataOutputStream`. The code looks like this:
|
|
|
|
|
|
```Java
|
|
|
if(e.getSource() == setButton) {
|
|
|
try {
|
|
|
String kpString = kpField.getText();
|
|
|
int kp = new Integer(kpString).intValue();
|
|
|
dos.writeInt(kp);
|
|
|
String kiString = kiField.getText();
|
|
|
int ki = new Integer(kiString).intValue();
|
|
|
dos.writeInt(ki);
|
|
|
String kdString = kdField.getText();
|
|
|
int kd = new Integer(kdString).intValue();
|
|
|
dos.writeInt(kd);
|
|
|
String scaleString = scaleField.getText();
|
|
|
int scale = new Integer(scaleString).intValue();
|
|
|
dos.writeInt(scale);
|
|
|
String newOffsetString = newOffsetField.getText();
|
|
|
int newOffset = new Integer(newOffsetString).intValue();
|
|
|
dos.writeInt(newOffset);
|
|
|
dos.flush();
|
|
|
} catch (Exception ex) {
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
When the buttons were working we just needed a way for the `value` and `pid_val` to be updated continuously. This was accomplished using an infinite loop that calls the function `refreshValues()` which just reads the two integers from the `DataInputStream`. The code looks like this:
|
|
|
|
|
|
```Java
|
|
|
public static void main(String[] args) {
|
|
|
PCpidController frame = new PCpidController();
|
|
|
frame.setVisible(true);
|
|
|
|
|
|
// Read PID and light value and update display.
|
|
|
while (true) frame.refreshValues();
|
|
|
}
|
|
|
|
|
|
private void refreshValues() {
|
|
|
try {
|
|
|
int pid = dis.readInt();
|
|
|
pidField.setText("" + pid);
|
|
|
int value = dis.readInt();
|
|
|
valueField.setText("" + value);
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Nice værdier til længste run:
|
|
|
KP: 100
|
|
|
KI: 35
|
|
|
KD: 65
|
|
|
Scale: 15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Exercise 3
|
|
|
|
|
|
### Exercise 4
|
|
|
|
|
|
## Conclusion
|
|
|
|
|
|
## References
|
|
|
[1], [Exercise material](http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson5.dir/Lesson.html)
|
|
|
[2], [Exercise material](http://www.philohome.com/nxtway/nxtway.htm)
|
|
|
|
|
|
|