Lego Segway Challenge: an introduction to embedded control

Tips and tricks for making a SegWay

Now its time for you to make your own lego segway. A few things that should be considered is listed below.

Wheels and gears

When building the SegWay consider if its torque or speed that you are after. Might be wise to choose the dimensions of the wheels, and possibly even gears, with this in mind. This can make or break your project.

Dimension of the SegWay

You should also consider what dimension your machine should have. Consider what information we have about how the mass and lenght of the pendulum affects the speed of the system. Idealy you want as slow speed as possible to be able to stabilize the pendulum more easily.

Variables in programming

The Mindstorm unit rounds of all the numbers to integers, for instace 2.45 becomes 2. This can make a huge difference (especially when it comes to the drift and integration). You should find a way to handle this.

Tuning of the constants

Remember that the constants for the control mechanism is really important to be tuned properly. If it can’t balance immidiatly then this is probably the problem.

Base contol when reference velocity is not zero

For the crane, we wanted the base to come to rest, i.e. the reference velocity was zero. In your case, you might want the reference velocity to be different than zero. One way to deal with this is to let the reference position be a ramp rather than a constant, i.e., to use

#define REF_DELTA=1;

int ref_pos=0;

...
ref_pos=ref_pos+REF_DELTA;
error=ref_pos-x;
...

Here, there is an apparent risk for overflow in the variable ref_pos, so an alternative could be to immediately hard code the reference velocity into the PID control algorithm, i.e. to use
 frac{d}{dt}e(t)= frac{d}{dt} x_{rm ref}(t)-frac{d}{dt}x(t) = v_{rm ref}-frac{d}{dt}x(t) approx v_{rm ref}-(x(t)-x(t-T))/T
Yet another solution could be to use a PID controller that tries to control the velocity of the base rather than its position. Feel free to explore these options!