Point class - Possible to get the current Position?

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

Moderators: roger, gloomyandy, skoehler

Point class - Possible to get the current Position?

Postby leJosNeedHelp » Tue Feb 18, 2014 9:25 am

Hi guys,

is it possible to get the current position of my ev3?
At the point class you have to set the start-point, i set it to (0|0) with
Code: Select all
Point p=new Point(0,0);

Now i want to travel a specified distance, for example 100 with the following code:
Code: Select all
final DifferentialPilot pilot = new DifferentialPilot(33, 185.0, Motor.C, Motor.B);
pilot.travel(100);


Is it possible to get the new position(after my ev3 travelled 100) in a new point object?
I tried this:
Code: Select all
Point p=new Point(0,0);
   LCD.clear();
   LCD.refresh();
   LCD.drawString("P0 "+p.x+"|"+p.y, 0, 0);
   pilot.travel(100);
   Point p2=new Point(p.angle());
   LCD.drawString("P1 "+p2.x+"|"+p2.y, 0, 1);
   LCD.refresh();


But the Output was every time:
P0: 0.0|0.0
P1: 1.0|-0.0.
I tried to increase the distance to 500, but the Output was the same ...


Any Ideas?
Thank you :-)
leJosNeedHelp
New User
 
Posts: 18
Joined: Tue Sep 24, 2013 7:33 am

Re: Point class - Possible to get the current Position?

Postby lawrie » Tue Feb 18, 2014 12:47 pm

Pilots do not update the position (or pose) of the robot for that, you need a pose provider. The simplest is OdometryPoseProvider.

You can do:

PoseProvider pp = new OdometryPoseProvider(pilot);

After doing this, whenever the pilot moves the robot, the pose provider calculates the new Pose (position and heading) of the robot.

To get the pose, you do:

Pose pose = pp.getPose();

If you want just the (x,y) location of the robot, you do:

Point location = pose.getLocation();
lawrie
leJOS Team Member
 
Posts: 835
Joined: Mon Feb 05, 2007 1:27 pm

Re: Point class - Possible to get the current Position?

Postby leJosNeedHelp » Tue Feb 18, 2014 1:19 pm

Thank you very, very much !
It works :-)!
leJosNeedHelp
New User
 
Posts: 18
Joined: Tue Sep 24, 2013 7:33 am


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff