GELway - Self Balancing Robot with Self Reset

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Sencond Control Loop Help

Postby borbon_juggler » Fri Feb 05, 2010 7:43 pm

Dear Steve , i don't have a big background in tuning LQR control system i have been reading a lot, but i don't find a book/web where teach you tecniques to chose the Q matrix and the P, and i like to add to the gelway a second control loop wich calculate the pwm offset to mantein the gelway in a desired body yaw angle, for make more easy the navegation. can you help me to calculate that ?.

best regards

Philip
borbon_juggler
New User
 
Posts: 6
Joined: Wed Jan 20, 2010 4:45 pm

Postby iWitzand » Fri Feb 12, 2010 12:23 pm

Hey Phillip, the LQR was one of the harder things for me to understand. I best it off the NXTway-GS documentation, it should be floating around in one of my references. My superviser for the project was like a Control Systems guru so he sought of steered me through the LQR. I used Matlab to determine Q and P values.

In regards to the second loop I believe it could be possible but it really isn't my strong point, and I probably be less help then good. During my project I tried to contact the NXTway-GS people but never got a response, maybe you might have better luck.

Steve
iWitzand
Novice
 
Posts: 30
Joined: Tue Jun 09, 2009 8:27 am

Marvin Servo Controller

Postby borbon_juggler » Mon Feb 15, 2010 8:02 pm

Hi Steve, again following your steps, I have been trying to simulate the diagram of Figure 2.6: Marvin servo controller block diagram, using the files GELway.my GELway Controller.m, but the simulation did not converge, and i know that the files are correct because the simulation of the digram of NXTwayGS works fine, could you share the filesystems. mdl with me?, plus can you tell me why you say that the first signal is thetha_ref-thetha if in the figure 2.6 is thetha-thetha_ref? appreciate your help

best regards

Philip
drymangalink (at) hotmail (dot) com
borbon_juggler
New User
 
Posts: 6
Joined: Wed Jan 20, 2010 4:45 pm

Cant get the program to work with lejos 0.8.5

Postby plugin » Mon Mar 08, 2010 5:22 pm

Hi all,

I've been trying to get this program working with no luck. I've compiled the source code with Lejos 0.8.5. I have made the following changes:
- Change the "port.readValue()" with "gyro.readValue()" using the class GyroSensor in Lejos. If I try to read directly from the port I always get a 0 value.
- Delete the EOPD code, since I am not using this sensor.

The program compiles well but the robot doesnt get upright. I've been watching at the values that I get from the Gyro Sensor and I think is not working well. When it get calibrated I get a value of "3" for the offset. Then, when the robot tilt the values from the gyro are in the range +/- 0-100. I've read that you get an offset of 600 aproximately and a values of the gyro acceleration between 0 al 1023. is this correct? I think the problem could be that the code is made for a range of values from 0 to 1023 not from 0 to 100 that is what I'm getting.

What value you obtain for the offset? And what range for the gyro acceleration?

Do you have some ideas?

Thanks in advance, and nice project!!!
plugin
New User
 
Posts: 4
Joined: Mon Mar 08, 2010 5:21 pm

Postby plugin » Tue Mar 09, 2010 9:47 pm

I found the problem! Now the bot get upright well!!!

The problem was that the class GyroSensor from Lejos has it own routine to calculate the offset. This way the offset was calculated 2 times, one in the GyroSensor and another in the GyroscopeSensor.

I fix this using an ADSensorPort and reading the values with "readRawValue" instead of using the GyroSensor class.

Fantastic!
plugin
New User
 
Posts: 4
Joined: Mon Mar 08, 2010 5:21 pm

Postby Vindl » Mon Mar 22, 2010 10:06 pm

plugin wrote:I found the problem! Now the bot get upright well!!!

The problem was that the class GyroSensor from Lejos has it own routine to calculate the offset. This way the offset was calculated 2 times, one in the GyroSensor and another in the GyroscopeSensor.

I fix this using an ADSensorPort and reading the values with "readRawValue" instead of using the GyroSensor class.

Fantastic!


I had the some problem. Could you please post your code (modified gyroscope sensor class) cause I would like to see your solution with ADSesnsorPort?

Mine is working fine now, I've added gyro.setOffset(0) after each gyro.readValue() call. If anyone needs working version of GELway for 0.85 I could send you my modified source files.
Vindl
New User
 
Posts: 1
Joined: Sat Feb 13, 2010 5:59 pm

Postby plugin » Fri Mar 26, 2010 7:26 pm

Hi Vindl,

the solution is easy. I simply declare a ADSensorPort var ant the use port.readRawValue().

This is my code:

Code: Select all
/**
 * This class is designed to work with the HiTechnic Gyrosensor. It has methods to calculate
 * the gyro offset, and find the gyro's angle and velocity. It has been modified by the
 * original programmers Bent Bisballe Nyeng, Kasper Sohn and Johnny Rieper
 *
 * @author Steven Jan Witzand
 * @version August 2009
 */
public class GyroscopeSensor
{
   private ADSensorPort port;
   private double angle = 0.0;
   private int lastGetAngleTime = 0;
   private double lastOffset = 0;
   private final double a = 0.999999;// Weight of older offset values.
   
   /**
    * The GyroscopeSensor constructor.
    *
    * @param port The NXT Sensor port the gyro sensor is connected to.
    */
   public GyroscopeSensor(ADSensorPort port)
   {
      this.port = port;
     
     this.port.setTypeAndMode(SensorConstants.TYPE_CUSTOM, SensorConstants.MODE_RAW);
      calcOffset();
   }

   /**
    * Calculates the offset specific to the HiTechnic gyro sensor. Needs to read the gyro
    * sensor in a stationary position.
    */
   public void calcOffset()
   {
      lastOffset = 0;
      double offsetTotal = 0;
      LCD.drawString("Calibrando Gyro", 0, 2);
      for (int i = 0; i < 50; i++) {
        offsetTotal += (double) port.readRawValue();
         try {
            Thread.sleep(4);
         } catch (InterruptedException e) {
         }
      }
      while (!Button.ENTER.isPressed()) {
         lastOffset = Math.ceil(offsetTotal / 50) + 1;
         LCD.drawString("Calibracion OK", 0, 4);
         LCD.drawString("OFFET: " + lastOffset, 2, 5);
         LCD.drawString("Pulsa Enter!", 1, 6);
      }
      try {
         Thread.sleep(500);
      } catch (InterruptedException e) {
      }
   }

   /**
    * Gets the angle offset of the gyro. Uses a recursive filter to attempt to account for
    * the gyro drift.
    *
    * @return A double containing the current gyro offset value.
    */
   private double getAngleOffset()
   {
      double offset = lastOffset * a + (1.0 - a) * (double) port.readRawValue();
      lastOffset = offset;
      return offset;
   }

   /**
    * Get the angle velocity of the gyro sensor.
    *
    * @return A double containing the angular velocity of the gyro sensor in degrees per
    *         second
    */
   public double getAngleVelocity()
   {
      double offset = getAngleOffset();
      return (double) port.readRawValue() - offset;
   }

   /**
    * Get the calculated gyro angle (angular velocity integrated over time).
    *
    * @return The angle in degrees.
    */
   public double getAngle()
   {
      int now = (int) System.currentTimeMillis();
      int delta_t = now - lastGetAngleTime;

      // Make sure we only add to the sum when there has actually
      // been a previous call (delta_t == now if its the first call).
      if (delta_t != now) {
         angle += getAngleVelocity() * ((double) delta_t / 1000.0);
      }
      lastGetAngleTime = now;

      return angle;
   }

   /**
    * Reset the gyro angle
    */
   public void resetGyro()
   {
      angle = 0.0;
      lastGetAngleTime = 0;
   }

}


I hope this could help.

Bye!
plugin
New User
 
Posts: 4
Joined: Mon Mar 08, 2010 5:21 pm

Postby galefabio » Thu Feb 03, 2011 10:46 am

Hi,
can you tell me how did you disable the eopd sensor ?? or if is less troubling for you can you send me your working code for the GELway ?

thank you,
regards !
galefabio
New User
 
Posts: 2
Joined: Thu Jan 27, 2011 5:21 pm

Re: GELway - Self Balancing Robot with Self Reset

Postby sammy » Tue Aug 02, 2011 9:18 am

I would also like to know, how to disable EOPD code. Thanks.
sammy
New User
 
Posts: 2
Joined: Tue Jul 19, 2011 1:56 pm

Re: GELway - Self Balancing Robot with Self Reset

Postby gloomyandy » Tue Aug 02, 2011 11:26 am

For any of you interested in a Segway robot, you should take a look at leJOS 0.9.0 there is a new sample program SegwayPilotDemo, that provides pretty much everything you need to get a Segway up and running...


Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4084
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: GELway - Self Balancing Robot with Self Reset

Postby iWitzand » Sat Aug 27, 2011 12:00 am

Hey, sorry haven't been on here in ages. The source code for the robot can be found at http://code.google.com/p/gelway/ As for disabling the EOPD sensor, let me know if you still need help, and I can revisit my code, it's probably written in my thesis somewhere, it's been a few years
iWitzand
Novice
 
Posts: 30
Joined: Tue Jun 09, 2009 8:27 am

Previous

Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff