EV3GyroSensor in 0.5.0

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

EV3GyroSensor in 0.5.0

Postby jietan » Mon Feb 10, 2014 1:25 am

Hi,

I am trying to build a Segway using EV3 and Lejos.
However, I met difficulties when reading values from EV3GyroSensor, probably due to my misuse of this class. Could anyone help me and tell me what is wrong for the following code snippet? Thanks a lot.

Port port = LocalEV3.get().getPort("S1");
EV3GyroSensor gyro = new EV3GyroSensor(port);
gyro.reset();
float[] sample = new float[1];
int counter = 0;
while (true)
{
if (Button.ESCAPE.isDown())
{
break;
}

gyro.getAngleMode().fetchSample(sample, 0);

if (counter % 100 == 0)
{
LCD.clear();
LCD.drawString("TestGyro", 3, 3);
LCD.drawString("Angle:", 0, 5);
LCD.drawString(""+sample[0], 10, 5);
}
counter++;
}
gyro.close();
jietan
New User
 
Posts: 3
Joined: Mon Feb 10, 2014 1:16 am

Re: EV3GyroSensor in 0.5.0

Postby jietan » Mon Feb 10, 2014 2:07 am

I think that I figured it out. The misbehavior is due to the connection between the sensor and the brick. After I changed from S1 port to S2 port, the problem was resolved.

I have a different question, though. I wonder whether I can get both the angle and the rate simultaneously from the gyro sensor. If I call

gyro.getAngleMode().fetchSample(sample, 0);
gyro.getRateMode().fetchSample(sample, 1);

the angle will be reset when switching to the RateMode. What is the correct way to get both the angle and the rate? Thanks.
jietan
New User
 
Posts: 3
Joined: Mon Feb 10, 2014 1:16 am

Re: EV3GyroSensor in 0.5.0

Postby Aswin » Mon Feb 10, 2014 3:22 pm

Hi,

There are some known issues with port 1 as you have discovered.

You cannot get both angle and rate from this sensor. Whenever you change from one o the other the sensor has to change to a different mode. Angle info is lost in the process.

You can however calculate angle from rate yourself using filters. The IntegrationFilter helps to convert rate to angle, the SampleThread filter helps you to do this on a regular basis. The OffsetCorrectionFilter helps to correct for offset drift. The results do not match the performance of the sensor though.

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 199
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: EV3GyroSensor in 0.5.0

Postby jietan » Mon Feb 10, 2014 4:14 pm

Thanks, Aswin.

When I program using LEGO Mindstorm software, it allows me to retrieve both the angle and the rate simultaneously. I wonder whether the current limitation is due to the hardware or due to the current stage of development of Lejos.
jietan
New User
 
Posts: 3
Joined: Mon Feb 10, 2014 1:16 am

Re: EV3GyroSensor in 0.5.0

Postby roger » Fri Mar 28, 2014 11:54 pm

Hi all,
For the past week my EV3Gyro sensor has been giving trouble. After a robot rotation, the reported angle change is about half the amount of rotation.
Here is the test program:
Code: Select all
   public static void main(String[] args) {
      p = new DifferentialPilot(5.6, 9.25, Motor.A, Motor.D);
      lejos.hardware.port.Port port = LocalEV3.get().getPort("S2");
      gyro = new EV3GyroSensor(port);
      angleProvider = gyro.getAngleMode();
      p.setTravelSpeed(30);
      p.setRotateSpeed(360);
      int accel = 60;
      p.setAcceleration(accel);
      opp = new OdometryPoseProvider(p);
      gyro.reset();
      Sound.beepSequenceUp();
      report("START acceleration " + accel);
         p.rotate(45);
         report("R 45");
         p.rotate(90);
         report("R 90");
         p.rotate(45);
         report("R 45");
         p.rotate(-180);
         report("R -180");
   }

   public static void report(String message) {
      Delay.msDelay(100);
      float heading = opp.getPose().getHeading();
      float[] angle = { 0 };
      angleProvider.fetchSample(angle, 0);
      System.out.println(message + " H " + heading + " A " + angle[0]);
   }
The output from in the EV3Control console window is :
START acceleration 60 H 0.0 A -0.0
R 45 H 45.405403 A 21.0
R 90 H 134.7027 A 64.0
R 45 H 179.5027 A 87.0
R -180 H -0.6054077 A -4.0
Has anyone else had this problem? or can reproduce this kind of result?
BTW, it seemed to be working OK about 2 weeks ago, but I did not do extensive testing then.
Roger
roger
Moderator
 
Posts: 359
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff