movePilot questions

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

Moderators: roger, gloomyandy, skoehler

fhbc2003
New User
Posts: 12
Joined: Thu Nov 12, 2009 6:18 pm

movePilot questions

Postby fhbc2003 » Tue Jan 17, 2017 8:47 pm

Hi, just getting started with leJOS .91 and the movePilot.

With the travel command, the robot behaves as expected. However, with the backward/forward command, the pilot appears to ignore the acceleration and speed that we set. Is this correct behavior or are we doing something wrong? From the API, it appears to me the forward speed should be adjusted when the linear speed is adjusted. (BTW the API repeatedly says "NXT"; I assume this is in error?)

Sample code with low speed/acceleration to show this behavior:

Code: Select all

public class test2EV3 {
   
      static float wheelDiameter = 8.15F;
      static float wheelBase = 14.60F;   
      static RegulatedMotor a1 = new EV3LargeRegulatedMotor(MotorPort.A);
      static RegulatedMotor b1 = new EV3LargeRegulatedMotor(MotorPort.B);      
      static MovePilot pilot = new MovePilot(wheelDiameter, wheelBase, a1, b1, true);
      
   public static void main(String[] args) {
      
while(Button.ESCAPE.isUp())
{
      LCD.drawString("Press any key to begin.", 0, 0);
      Button.waitForAnyPress();   
      pilot.setLinearAcceleration(20);
      pilot.setLinearSpeed(20);    
      pilot.travel(40);
      pilot.backward();
      Sound.pause(600);
      pilot.stop();
   
   } //ends while loop
   } //ends main
}

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

Re: movePilot questions

Postby gloomyandy » Tue Jan 17, 2017 10:05 pm

What do you expect that to do? You are only giving the backward command 600mS (so just over half a second) to operate!
backward and forward return immediately they do not wait for the robot to move or anything.
leJOS news https://lejosnews.wordpress.com/

fhbc2003
New User
Posts: 12
Joined: Thu Nov 12, 2009 6:18 pm

Re: movePilot questions

Postby fhbc2003 » Tue Jan 17, 2017 11:50 pm

Well, honestly, I expected the same behavior since the distances traveled were the approximately the same for both methods.

I retested the robot over a much larger distance, and the average speed for both methods was about the same. So it appears the change in behavior was due to acceleration. Does the forward command use a default acceleration?

Maybe I should explain the real problem we are trying to solve. I'm helping students who want their robot to touch to a wall and then move away from it in a straight line. If they simply use the travel command, sometimes there is a stall when the robot bumps the wall; when that happens the next move is unpredictable (the robot jerks to the left or right).

Using

Code: Select all

pilot.travel(-10,true);
 while(pilot.isMoving())Thread.yield();
does not seem reliable, either. Can you suggest a better way to detect a stall/ensure the robot leaves the wall smoothly? I am not an experienced programmer and this is really frustrating the kids.

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

Re: movePilot questions

Postby gloomyandy » Wed Jan 18, 2017 12:17 am

I don't think you understand the nature of things like isMoving, they only tell you that the pilot command that your previously issued (in this case the travel) is still in progress, they do not magically detect that your robot has hit a wall. So in this case the motors will continue to run until the travel command has completed the requested distance. If the robot hits a wall that will not make any difference (other than physically stopping it), it is very unlikely that the robot will remain straight. If you want to detect a wall and stop before hitting it (which is the only sure way you will avoid disrupting the robot travel), then you will need to use some kind of sensor and monitor the sensor during the move.

Also I'm not at all sure as to how you have been comparing the use of travel with forward and backward. All three should make use of the acceleration and speed settings. However, travel will move a set distance before returning (unless you use the form that specifies immediate return), but foward and backward will simply start the move and return, so you will have to find other ways to monitor the movement. So for instance in the code you previously posted the backward command would only have run the motors for 600mS before stop was called. Perhaps you can provide a better example and explain what you expect to happen and what actually happens.
leJOS news https://lejosnews.wordpress.com/

fhbc2003
New User
Posts: 12
Joined: Thu Nov 12, 2009 6:18 pm

Re: movePilot questions

Postby fhbc2003 » Wed Jan 18, 2017 4:18 pm

To test travel vs. forward, I ran the following:

Code: Select all

pilot.setLinearAcceleration(20);
      pilot.setLinearSpeed(20);    
      pilot.travel(200);
      Button.waitForAnyPress();
      pilot.backward();
      Sound.pause(10000);
      pilot.stop();

With this code, the robot traveled about 12' in each direction, and the travel time was roughly the same. The robot being used is somewhat top-heavy. Executin 'travel', it accelerated and decelerated smoothly, with no listing. Executing 'backward', the robot leaned heavily both when starting and stopping. I can't measure the acceleration, but the effects are easy to see given the robot's high center-of-gravity.

I don't think you understand the nature of things like isMoving

That certainly is true, and of a lot more than isMoving. For example, I didn't encourage sensors because until recently I didn't understand enough Java to figure out how to use even the touch sensor! Previous students using NXTs preferred using the wall over touch sensors to straighten the robot (they never had issues with stalls), so this crop followed their example.

The reason I thought isMoving detected stalls is because I read the following in the API for movePilot:
Handling stalls: If a stall is detected, isStalled() returns true , isMoving() returns false, moveStopped() is called, and, if a blocking method is executing, that method exits.
I thought that it was saying that isMoving() would be false if there was a stall, as well as when the move was finished. What is the proper method for detecting a stall?

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

Re: movePilot questions

Postby gloomyandy » Wed Jan 18, 2017 4:48 pm

It is possible you are seeing a bug with forward/backward, the MovePilot is pretty new code and has not been used that much. You could always create your own class that replaces backwards and forwards with calls to travel(-<large distance>, true) and travel(<large distance>, true) as this will do pretty much the same thing.


As to using stall detection, the problem is that it can be very hit and miss. If your robot hits a wall, then the wheels may continue to turn (if they slip on the surface), so using that as a detection mechanism is probably not very reliable. Also when you hit a wall you will pretty much always lose track of your current position as calculated using odometry which is usually not a good idea. I know that in things like FLL teams will often square the robot up by driving into a wall, so I can see how this may help in some situations. In which case stall detection may be ok. But it is a pretty crude solution.
leJOS news https://lejosnews.wordpress.com/

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

Re: movePilot questions

Postby gloomyandy » Wed Jan 18, 2017 4:54 pm

Oh and you should probably not use Sound.pause to add a delay, it really isn't intended for general use, try using Delay.msDelay (or one of the other methods in the delay class) instead.
leJOS news https://lejosnews.wordpress.com/

fhbc2003
New User
Posts: 12
Joined: Thu Nov 12, 2009 6:18 pm

Re: movePilot questions

Postby fhbc2003 » Wed Jan 18, 2017 6:23 pm

I'll update our delay method. We're not too worried about odometry: with the mats used in the competitions we attend, slippage is the rule even on turns. One of the realities we just have to deal with. So odometry just doesn't work for our situation.

Your suggestion with the 'travel(<large distance>, true)' should solve our problem. It seems the obvious solution now that you've pointed it out to me. Many thanks for your time and patience on this, and for leJOS itself.

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

Re: movePilot questions

Postby gloomyandy » Wed Jan 18, 2017 7:41 pm

No problem, can you provide some details of the competitions you are taking part in? Would be interesting to find out a little more.
leJOS news https://lejosnews.wordpress.com/

fhbc2003
New User
Posts: 12
Joined: Thu Nov 12, 2009 6:18 pm

Re: movePilot questions

Postby fhbc2003 » Wed Jan 18, 2017 9:10 pm

The organization that sponsors our competitions is called TCEA (Texas Computer Education Association). We participate in the "arena" competition. Lego robots are used (NXT or EV3); unlimited Lego-branded parts are allowed but no other brand of sensors, etc. The game surface is what used to be Lego's Race-against-time mat (4' x 4'; placed on a plywood board with 4" walls). Matches last 2 minutes, and points are usually scored by moving different game pieces to (or removing them from) designated areas on the mat. Pinpoint accuracy is required for maximum points.

This competition permits the use of any programming language. I felt our high school students needed exposure to text-based programming, and given the popularity of Java, we went with leJOS. For most of the kids I coach, this is their first experience with programming. So I give them a starter file (more or less the first code I posted). They have to determine the wheel diameter and track width for their robot, and then write the program that accomplishes their goals.

Granted, I'm not really teaching these students much Java per se (hard to in a club that at most meets 1-2 days per week), but at least they are being exposed to text-based programming. At the least, they are learning a lot of important lessons about matching parentheses and avoiding typing errors!

I am very grateful to all of those who have worked to make leJOS available to us. One side benefit is that it seems to be more accurate than Mindstorms. (With leJOS, we have won several regional competitions and once at the state level; for several years in a row, the winning robot at TCEA's state competition was programmed with leJOS or, in one case, RobotC.) More importantly, our use of leJOS started a chain of events that eventually led the school, this year, to offer a Computer Science class. Your work is impacting the next generation!

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

Re: movePilot questions

Postby gloomyandy » Wed Jan 18, 2017 11:03 pm

Thanks for the info! Sounds like a great idea. Hope it all goes well!
leJOS news https://lejosnews.wordpress.com/

Aswin
leJOS Team Member
Posts: 310
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: movePilot questions

Postby Aswin » Wed Jan 25, 2017 10:11 pm

Nice to hear that lejos works well for you.

I have tracked down and corrected the bug you discovered. The forward and backward methods will work properly in the next release. One other bug will then be gone too. This one could be triggered when making very small speed changes.

Aswin
My NXT blog: http://nxttime.wordpress.com/

steveiswicked
Novice
Posts: 33
Joined: Sun Feb 06, 2011 11:22 pm
Contact:

Re: movePilot questions

Postby steveiswicked » Mon Nov 13, 2017 7:41 am

Hi Aswin, Is there any chance I could get an early copy of the revised movePilot forward and backward classes?
Regards
Stee

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

Re: movePilot questions

Postby gloomyandy » Mon Nov 13, 2017 8:04 am

You can always get the most recent versions of our source from sourceforge. I will let Aswin confirm but as far as I can tell no changes have been made to the MovePilot, he did however update the WheeledChassis to fix the bugs mentioned in this thread. The most recent WheeledChasis code is here....
https://sourceforge.net/p/lejos/ev3/cod ... assis.java
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest