søndag den 4. oktober 2009

Lab session 4

25092009
Attendes: Jesper Jakobsen, Mads Hansen Lund og Michael Nygaard Pedersen
Goal
The goal is to build and code a two wheel self-balancing robot based on the NXT main unit.

Sub goals
The robot software and construction should be based on the software from Ref1. This demanding task should outline the limitations with the NXT (including sensor) and embedded Java as a development environment.

Plan
· Build and evaluate the robot from Ref1
· Code the robot and evaluate the result based on default coefficients
· Experiments involving different environments to evaluate the performance of the light sensor
· Evaluate the PID regulator performance with different coefficients

Results
PIDThe lab session made it obvious that the NXT has its limitations. There is of cause quantization issues, sampling time issues and saturation issues when implementing a “high speed” control algorithm. All the issues are illustrated in a simplified way in Figure 1.








Figure 1 - Simplified control model

The NXT motor is modeled as a simple first order transfer function and the quantizer is modeling the A/D converter in the light sensor. The useful resolution is experienced as 10 bit. The OptoGain is assuming a linear relationship between the motor correction and measurement (This is only true, if the robot is tilting back and forth without moving back or forth). The saturation is implemented because of the motor power interval.
Figure 2 shows the simplified motor step response, which indicates all the mentioned issues. The sampling frequency is assumed to be 200Hz. The system pole is set with respect to sampling frequency and has an oscillation frequency around 10Hz (related to system pole).









Figure 2 - Step response with default coefficients

Description of experiment
The experiment deals with the well known concept of a balancing two wheeled robot (Ref2).
PID (proportional-integral-derivative) controller
The PID controller has three control parameters, which is known proportional, integral and derivative respectively (shown in Figure 3). The proportional parameter regulates directly from the error, which in our case is the "distance" error. If the proportional parameter is too big, it will result in an excessive over shoot, which will put the robot unwieldy state. The proportional regulator maintains a steady state error of the distance. The steady state error is optimized by the integral parameter. The integral parameter regulates on a integrated value of the distance error integrated by Euler integral.
By increasing the proportional - and the integral parameters the over / under shoot grows “proportional”. The over / under shoot maintains in unwieldy state for the robot. Instead of decreasing the proportional - and the integral parameters the derivative parameter can be used. The derivative parameter regulates on the slope from the error. The slope from the error is in our case the speed.












Figure 3 – The block diagram showing concept of the PID controller (Ref3).

By observing the robot the parameters were adjusted based on this knowledge.
The code
A Sejway object is instantiated in the main method followed by different three method calls: sej.getBalance(), sej.pidControl() and sej.shutDown().
public static void main(String[] args) {
LCD.drawString("Level: ", 0, 0);
Sejway sej = new Sejway();
sej.getBalancePos();
sej.pidControl();
sej.shutDown();
}
The getBalance() method continuously assigns the current value read from the NXT light sensor to the global variable offset until the ENTER button is pressed. Offset is the setpoint used in the PID control algorithm.
The pidControl() method obviously contains the PID control algorithm, which determines a pid_val and sets the motor power (same for both motors) according to this calculated value. The polarity of pid_val determines the direction of the motors (i.e. forward or backwards).
A data logger routine was added to the pidControl() method (shown below).
DataLogger dl = new DataLogger("Sample.txt");
int posLevel;
posLevel = normVal - offset;
LCD.drawInt(posLevel,3,7,0);
dl.writeSample(posLevel);
A DataLogger object is instantiated. The current position is sampled and logged into a file named Sample.txt.
The pidControl() method loops until the ESCAPE button is pressed after which the NXT robot is shut down.

Observations
The robot was in all cases very rough in its way of adjusting the position and it was really balancing for more than a few seconds. It is possible to get it balancing; no doubt about that – but battery condition and harmonic light are the most important parameters.
It has become obvious that although the light sensor can be used for the experiment it is not the ideal sensor for the job. The limited time at this lab session was used to observe the behavior of the robot under different light condition, different surfaces with different coefficients.

Pictures of Lego model
Different approaches were investigated. Figure 4 shows the standard robot from Ref1.















Figure 4 - Picture of robot
Figure 5 shows a modified edition, where the light sensor measurement is mechanical amplified. This construction will improve the light sensor range and make the robot correspond quicker for a smaller angular error.















Figure 5 - Picture of modified robot

Problems encountered
The robot was very unstable in most cases and it impossible to get robot to balance for more than a few seconds. The battery was not able to be fully charged and this was also a problem, because the motor would not be powered with full effect.

Conclusion
Based on the simple simulation and observations from the experiments, it can be concluded that the setup lies very close to system oscillations frequency. That means if the battery is not fully charged the robot will oscillate because of the physics in the system. The robot will balance under the right conditions with a fine tuned PID, but a different approach must be considered if the system should work properly.
The code contains several mysterious factors, which might or might not be based on scientific calculations or measurements. But because of the limited time this was not investigated.

Ingen kommentarer:

Send en kommentar

Faste læsere