Announcement

Collapse
No announcement yet.

[Java] Need help with gyroscope and odometry.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Java] Need help with gyroscope and odometry.

    [Question updated]

    I am programming Robotino using Java language...

    I've found that the api2 contains a class called Odometry (rec.robotino.api2.Odemetry).

    I've also found that it contains the following methods related to Odometry class (any other methods are related to Object class):

    .mapFrameCoordinatesEvent(double arg0, double arg1, double arg2);
    .mapImagePixelCoordinatesEvent(int arg0, int arg1, double arg2);
    .readings(SWIGTYPE_p_double arg0, SWIGTYPE_p_double arg1,SWIGTYPE_p_double arg2);
    .readings(SWIGTYPE_p_double arg0, SWIGTYPE_p_double arg1,SWIGTYPE_p_double arg2, SWIGTYPE_p_unsigned_int arg3);
    .readingsEvent(double arg0, double arg1, double arg2, float arg3, float arg4, float arg5, long arg6);
    .set(double arg0, double arg1, double arg2);
    .set(double arg0, double arg1, double arg2, boolean arg3);
    .setComId(ComId arg0);
    .swigReleaseOwnership();
    .swigTakeOwnership();

    I know that I have to use the .setComId method to enable odometry just the way I did it with omnidrive, bumper and ir sensors.

    I know that I can't use the .readings methods because they require a SWIGTYPE_p_double variable type, so I suppose that those methods are internal inside the Odometry class.

    I am sure that I don't have to use .swigReleaseOwnership and .swigTakeOwnership because OmniDrive class has the same methods and the omnidrive system works without me calling those methods.

    I don't know what are .mapFrameCoordinaterEvent and .mapImagePixelCoordinatedEvent for. I think they have something to do with a 2D map made of what Robotino sees and detects.

    The remaining methods are .set(with boolean), .set(without boolean) and .readingsEvent.

    I don't know what are both .set used for.

    I also don't know if I need to use the .readingsEvent or if I should combine it with.set.

    As I understand when I plug in the gyroscope into a Robotino USB port, it works without the necessity of calling it, it is implemented in the Odometry class.

    If some one could help me understand this better, I would be very grateful. Please let me know if I am missing something.
    Last edited by Rusoski; 10-06-2015, 02:56 PM.

  • #2
    Hi Rusoski,
    I think you are mixing things. First of all, which page about methods do you refer to?
    You don't need to handle the gyroscope events since the gyroscope is only used to correct the internal odometry (I think). You can control the robot by reading the odometry which gives you the relative position the robot did travel. For example you tell the robot to travel and then check continuously if the distance is X and then stop. That's it.
    The northstar sensor is a different type of sensor, it gives absolute positions of the robot. In an ideal case, you wouldn't need the odometry any more by using it. So there is no fixed dependency between both (of course, you can use them to correct each other).

    Comment


    • #3
      Originally posted by misken View Post
      Hi Rusoski,
      I think you are mixing things. First of all, which page about methods do you refer to?
      You don't need to handle the gyroscope events since the gyroscope is only used to correct the internal odometry (I think). You can control the robot by reading the odometry which gives you the relative position the robot did travel. For example you tell the robot to travel and then check continuously if the distance is X and then stop. That's it.
      The northstar sensor is a different type of sensor, it gives absolute positions of the robot. In an ideal case, you wouldn't need the odometry any more by using it. So there is no fixed dependency between both (of course, you can use them to correct each other).
      Thank you so much for your reply!

      I am talking about Odometry.

      Which methods should I use to make it move?

      There are 4 available methods on the page:

      .setComId <--- This method is used to make odometry actually work
      .readings <--- This does not work
      .set <--- I don't know why is this method for.
      .readingsEvent <--- As I understand I should use this to make Robotino move to (distance(m) on x, distance(m) on y, final rotational position d, speed in x, speed in y, speed rotation, what is the sequence for?)

      There is no method to read the output of the odometry.

      I don't understand how it works, so I can not make it move...

      Could you please give me an example?
      Last edited by Rusoski; 10-02-2015, 02:45 PM.

      Comment


      • #4
        The odometry is nothing that makes the robot move. It's something that enables you to measure that the robot has moved (or is moving). As the name says - readingsEvent is somethin you READ not write. So you can read how the distance and the speed are at the moment, but you can't tell the robot to do anything.

        Comment


        • #5
          Take a look at this Java example (I found it in the SVN, I didn't test it myself), this should give you an idea how to make the robot drive (have an eye on "omniDrive")

          Code:
          import java.util.TimerTask;
          import java.util.Timer;
          
          import rec.robotino.api2.Bumper;
          import rec.robotino.api2.Com;
          import rec.robotino.api2.OmniDrive;
          
          
          /**
           * The class Robot demonstrates the usage of the most common robot component classes.
           * Furthermore it shows how to handle events and receive incoming camera images.
           */
          public class Robot
          {
              protected final Com _com;
              protected final OmniDrive _omniDrive;
              protected final Bumper _bumper;
          
              public Robot()
              {
                  _com = new MyCom();
                  _omniDrive = new OmniDrive();
                  _bumper = new Bumper();
                  
                  _omniDrive.setComId(_com.id());
                  _bumper.setComId(_com.id());
              }
              
              public boolean isConnected()
              {
                  return _com.isConnected();
              }
          
              public void connect(String hostname, boolean block)
              {
                  System.out.println("Connecting...");
                  _com.setAddress( hostname );
                  _com.connectToServer(block);
              }
          
              public void disconnect()
              {
                  _com.disconnectFromServer();
              }
              
              public void setVelocity(float vx, float vy, float omega)
              {
                  _omniDrive.setVelocity( vx, vy, omega );
              }
              
              public void rotate(float[] inArray, float[] outArray, float deg)
              {
                  float rad = 2 * (float)Math.PI / 360.0f * deg;
                  outArray[0] = (float)Math.cos(rad) * inArray[0] - (float)Math.sin(rad) * inArray[1];
                  outArray[1] = (float)Math.sin(rad) * inArray[0] + (float)Math.cos(rad) * inArray[1];
              }
              
              public void drive() throws InterruptedException
              {
                  System.out.println("Driving...");
                  float[] startVector = new float[] {0.2f, 0.0f };
                  float[] dir = new float[2];
                  float a = 0.0f;
                  while (_com.isConnected() && false == _bumper.value() )
                  {
                      //rotate 360degrees in 5s
                      rotate( startVector, dir, a );
                      a = 360.0f * _com.msecsElapsed() / 5000;
          
                      _omniDrive.setVelocity( dir[0], dir[1], 0 );
          
                      Thread.sleep(100);
                  }
              }
              
              /**
               * The class MyCom derives from rec.robotino.api2.Com and implements some of the virtual event handling methods.
               * This is the standard approach for handling these Events.
               */
              class MyCom extends Com
              {
                  Timer _timer;
                  
                  public MyCom()
                  {
                      _timer = new Timer();
                      _timer.scheduleAtFixedRate(new OnTimeOut(), 0, 20);
                  }
                  
                  class OnTimeOut extends TimerTask
                  {
                      public void run()
                      {
                          processEvents();
                      }
                  }
          
                  @Override
                  public void connectedEvent()
                  {
                      System.out.println( "Connected" );
                  }
          
                  @Override
                  public void errorEvent(String errorStr)
                  {
                      System.err.println( "Error: " + errorStr );
                  }
          
                  @Override
                  public void connectionClosedEvent()
                  {
                      System.out.println( "Disconnected" );
                  }
              }
              
              public static void main(String args[])
              {
                  String hostname = "192.168.5.5";
                  if( args.length == 1)
                  {
                      hostname = args[0].toString();
                  }
                  
                  Robot robotino = new Robot();
                  
                  try
                  {
                      robotino.connect(hostname, true);
                      robotino.drive();
                      robotino.disconnect();
                  }
                  catch (Exception e)
                  {
                      System.out.println(e.toString());
                  }
              }
          }
          Be aware that the comment in the beginning tells something about receiving camera images. It doesn't as far as I can see. It makes the robot drive in a circle as long as the bumber is not activated. And also check the IP address used there, I guess it won't be the same as at your setup.
          Last edited by misken; 10-07-2015, 02:32 PM.

          Comment

          Working...
          X