iCommand Localisation Problem

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

Moderators: 99jonathan, roger, imaqine

iCommand Localisation Problem

Postby Jochi » Tue Feb 12, 2008 8:56 pm

Hello,

I have been trying to run the following code (adapted from Brians Maximum NXT book - Chapter 12) using iCommand instead of LeJOS.

Code: Select all
import icommand.navigation.*;
import icommand.nxt.*;
import icommand.nxt.comm.NXTCommand;

public class Localisation_test {

   TachoNavigator move;
   public Localisation_test() {
      move = new TachoNavigator(5.6F, 13.5F, Motor.C, Motor.B, false);
   }
   
   public static void main(String [] args) {
      
      TachoNavigator robot = new TachoNavigator(5.6F, 13.5F, Motor.C, Motor.B, false);
      Localisation_test robot = new Localisation_test();
      
      NXTCommand.open();
      
      robot.move.goTo(50, 0);
      robot.move.goTo(25, 25);
      robot.move.goTo(25, -12.5);
      robot.move.goTo(0, 0);
      
      NXTCommand.close();
      
   }
      
}


But all that happens is that the robot just travels in a straight line non-stop. It never attempts to change direction.
I have tried all kinds of different combinations of obtaining the same behaviour but with no success. Can anyone see what's going wrong? It's no doubt something obvious that I'm missing.

I'm running iCommand 0.6 with NXT firmware 1.05.

Cheers,
Jochi

P.S. Probably a stupid question, but can iCommand (0.6 or 0.7) run with the new version of LeJOS as the firmware? If so are there any tutorials anywhere which help with the setting up of basic programs using this config? I am somewhat confused over whether this is possible or not...

Thanks
User avatar
Jochi
Novice
 
Posts: 26
Joined: Tue Nov 06, 2007 8:17 pm
Location: Guildford, UK

Re: iCommand Localisation Problem

Postby bbagnall » Mon Feb 18, 2008 1:23 am

Code: Select all
import icommand.navigation.*;
import icommand.nxt.*;
import icommand.nxt.comm.NXTCommand;

public class Localisation_test {

   TachoNavigator move;
   public Localisation_test() {
      move = new TachoNavigator(5.6F, 13.5F, Motor.C, Motor.B, false);
   }
   
   public static void main(String [] args) {
      
      TachoNavigator robot = new TachoNavigator(5.6F, 13.5F, Motor.C, Motor.B, false);
      Localisation_test robot = new Localisation_test();
      
      NXTCommand.open();
      
      robot.move.goTo(50, 0);
      robot.move.goTo(25, 25);
      robot.move.goTo(25, -12.5);
      robot.move.goTo(0, 0);
      
      NXTCommand.close();
      
   }
      
}


You've got some strange things in there. TachoNavigator is initialized twice in your code (you use two separate constructors). Also, I'm not sure why you bother making an instance of Localisation_test with this line:
Localisation_test robot = new Localisation_test();

Really you should just do everything in the main() method and forget about making an instance of Localisation_test.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Postby Jochi » Wed Feb 20, 2008 6:30 pm

Hi Brian,

Thanks for your reply. I have altered the code based on your advice (please see below). Please excuse me my Java knowledge is rather limited.

However I'm still getting the same problem. The robot just keeps on going in a straight line, and does not navigate to any of the points indicated...

Do you have any idea what I'm doing wrong?

Thanks,
Jochi

Code: Select all
import icommand.navigation.*;
import icommand.nxt.*;
import icommand.nxt.comm.NXTCommand;

public class Localisation_test {
   
   public static void main(String [] args) {
      
      TachoNavigator robot = new TachoNavigator(5.6F, 13.5F, Motor.C, Motor.B, false);

      NXTCommand.open();
      robot.goTo(50, 0);
      robot.goTo(25, 25);
      robot.goTo(25, -12.5);
      robot.goTo(0, 0);
      NXTCommand.close();
   }   
}
User avatar
Jochi
Novice
 
Posts: 26
Joined: Tue Nov 06, 2007 8:17 pm
Location: Guildford, UK

Postby Gert » Thu Feb 21, 2008 11:12 pm

Hi Jochi,

I have more or less the same kind of problems. I noticed that when the argument in some methods is almost zero, the robot starts driving forward without stopping. For example with the rotate() and travel() method.

I replaced 0 with 0.1 and it still happens.

But if I replace the value 0 with a value of 1 or higher it seems to work. The robot drives in the right direction and stops.

In your example, I replaced the value 0 with the value 1 and than the robot makes almost the right moves. So the code is becomes:

Code: Select all
     NXTCommand.open();
      robot.goTo(50, 1);
      robot.goTo(25, 25);
      robot.goTo(25, -12.5);
      robot.goTo(1, 1);
      NXTCommand.close();


However, the robot didn't come back to the starting point and I assume that the last instruction should accomplish that.

I already replaced the Lego firmware with lejos NXJ 0.5 beta and use icommand-0.7.

Regards,
Gert
Gert
New User
 
Posts: 6
Joined: Sun May 13, 2007 3:40 pm
Location: Netherlands

Postby Jochi » Sun Feb 24, 2008 4:52 pm

Hi Gert,
Yes that has solved the issue thank you!!

The problem I have now is that while using the TachoNavigator class I cannot seem to read values from any sensors (in particular the Ultrasonic sensor).
No matter how I write the code in order to obtain a reading/reaction the sensors will just not return any readings. I have tried everything I can find on these forums too with no success :?

The code I'm trying at the moment is below: -

Code: Select all
import icommand.navigation.*;
import icommand.nxt.*;
import icommand.nxt.comm.NXTCommand;


public class Layer_Zero {

   UltrasonicSensor us;
   TouchSensor tsR;
   TouchSensor tsL;
   TachoNavigator move;

   public Layer_Zero() {

      move = new TachoNavigator(5.6F, 13.5F, Motor.B, Motor.C, true);
      us = new UltrasonicSensor(SensorPort.S1);
      tsR = new TouchSensor(SensorPort.S2);
      tsL = new TouchSensor(SensorPort.S4);
   }

   public void reachDestination(float x, float y){

      move.goTo(x, y);

      while(move.isMoving()) {
         try {Thread.sleep(100);} catch(Exception e) {}
         int distance = us.getDistance();
         if(distance < 20) {
            move.stop();
            Motor.A.rotateTo(90);
            int leftD = us.getDistance();
            Motor.A.rotateTo(-90);
            int rightD = us.getDistance();
            Motor.A.rotateTo(0);
            int jumpD = rightD > leftD?rightD:leftD;
            if(jumpD > 20) jumpD = 20;
            if (rightD > leftD) move.rotateTo(-90);
            else move.rotateTo(90);
            move.travel(jumpD);
            if (rightD > leftD) move.rotateTo(90);
            else move.rotateTo(-90);
            move.travel(jumpD);
            if (rightD > leftD) move.rotateTo(90);
            else move.rotateTo(-90);
            move.travel(jumpD);
            if (rightD > leftD) move.rotateTo(-90);
            else move.rotateTo(90);
            move.goTo(x, y);
         }
      }
   }

   public static void main(String[] args) {
      NXTCommand.open(); //Open Bluetooth Connection
      Layer_Zero robot = new Layer_Zero();
      Motor.A.setSpeed(200); //Head Rotation Speed
      robot.move.setSpeed(300); //Wheels Movement Speed
      robot.move.goTo(150,1);

      NXTCommand.close(); //Close Bluetooth Connection
   }

}



This is pretty much just a variation of the code from the Pathfinder program in the Maximum NXT book, except its made to run over icommand instead of on the brick.

Any ideas why the ultrasonic isn't returning anything? i.e. the robot just keeps on going and doesn't avoid any obstacles...

Thanks,
Jochi
User avatar
Jochi
Novice
 
Posts: 26
Joined: Tue Nov 06, 2007 8:17 pm
Location: Guildford, UK

Postby Gert » Mon Feb 25, 2008 10:42 pm

Hi Jochi,

In your code you are not calling reachDestination() but you call robot.move.goto(). If you change your main(), it will work better:

Code: Select all
   public static void main(String[] args) {
      NXTCommand.open(); //Open Bluetooth Connection
      Layer_Zero robot = new Layer_Zero();
      Motor.A.setSpeed(200); //Head Rotation Speed
      robot.move.setSpeed(300); //Wheels Movement Speed
      robot.reachDestination(150,10);

      NXTCommand.close(); //Close Bluetooth Connection
   }


Note: I changed the y value from 1 to 10. There seems to be a bug that values near to zero make the robot move without stopping. No idea what causes this. When I debug, it goes deep into the lower layers of Lejos. This is more something for the Lejos gurus.

You also have to modify the first move instruction in:

Code: Select all
  public void reachDestination(float x, float y){

      move.goTo(x, y,true);


You need the third boolean argument to make the method to return imediately. Otherwise the robot tries to go the full 150 cm before the method returns. With passing true to the method, the method call will directly return and the code within the while loop will work to avoid obstacles.

With these changes my robot did try to avoid the obstacles. However, it didn't really worked well because it managed to get stuck. The value of 20 was to small for my robot. I changed the jumpD to 50 to really avoid the obstacle. This is also how it is done in the book.

Code: Select all
if(jumpD > 50) jumpD = 50;


The last part of the reachDestination has a number too many rotateTo. I changed the code more or less back as it is in the book by removing the last three rotateTo().

Code: Select all
   public void reachDestination(float x, float y){

      move.goTo(x, y,true);

      while(move.isMoving()) {
         try {Thread.sleep(100);} catch(Exception e) {}
         int distance = us.getDistance();
         if(distance < 30) {
            move.stop();
            Motor.A.rotateTo(90);
            int leftD = us.getDistance();
            System.out.println("leftD="+leftD);
            Motor.A.rotateTo(-90);
            int rightD = us.getDistance();
            System.out.println("rightD="+leftD);
            Motor.A.rotateTo(0);
            int jumpD = rightD > leftD?rightD:leftD;
            if(jumpD > 50) jumpD = 50;
            if (rightD > leftD) move.rotateTo(-90);
            else move.rotateTo(90);
            move.travel(jumpD);
           
            reachDestination(x, y);
         }
      }


Because reachDestination() calls itself recursively it will (try to) reach the (x,y) coordinate after the evasive manouvres (rotate 90 degrees and travel 50 cm in that direction).

I tried the modified code and it works for me in a simple test that only needed one evasive manouvre.


I hope this helps,

Kind regards,
Gert
Gert
New User
 
Posts: 6
Joined: Sun May 13, 2007 3:40 pm
Location: Netherlands

Postby Jochi » Wed Feb 27, 2008 1:09 pm

Hi Gert,

Thank you again. I have made those changes and it works brilliantly :D

I agree with the simplifying of reachDestination. What I had previously posted was just the latest of my playing around with it.

Right, next I need to implement some sort of heuristics!

Thanks again for your help,
Jochi
User avatar
Jochi
Novice
 
Posts: 26
Joined: Tue Nov 06, 2007 8:17 pm
Location: Guildford, UK


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

cron
more stuff