Two Behavior Problems

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

Moderator: roger

Two Behavior Problems

Postby ltj » Sun May 18, 2008 6:25 pm

I want to build a robot that will have 3 bahaviors

1) drive randomly
2) drive to target
3) avoid obstacle

first problem is with random movement, to make it move at random I use two comands
Code: Select all
         NavClass.nav.rotate((float)( (Math.random() - 0.5) * 90));
         NavClass.nav.travel( (int)(Math.random() * 20) );

but I don't know how to loop them in behavior with out creating infinite loop

second problem is with other two behaviors, my target is point (100, 100), and behavior 2 is simply
Code: Select all
import josx.robotics.*;
import josx.platform.rcx.*;

public class DriveToTarget implements Behavior {

   public boolean takeControl() {
      return true;
   }

   public void suppress() {
      NavClass.nav.stop();
   }

   public void action() {
      //Sound.twoBeeps();
      NavClass.nav.gotoPoint(100,100);
   }
}

(takeControl() returns true only in current example because of the first problem (random movement))

and behavior 3
Code: Select all
public class HitWall implements Behavior {

   public boolean takeControl() {
      return !Sensor.S3.readBooleanValue();
   }
   
   public void suppress() {
      Sound.beep();
   }
   
   public void action() {      
      NavClass.nav.travel(-10);
      NavClass.nav.rotate(45);
      NavClass.nav.travel(10);
   }
}


the problem is that when my robot hit something it avoids obstacle and starts to move to (100,100) point but never reaches it, it stops in about (90,90) point, but LCD.showNumber() shows (100,100), the more obstacles are on its way the sooner it stops. NavClass have
Code: Select all
static TimingNavigator nav = new TimingNavigator(Motor.C, Motor.A, 8.000f, 3.9f);
so that I have global access to navigator. Is it because TimingNavigator, will the results be better if I would use RotationNavigator? (i couldn't check this because i don't have Rotation Sensors for now), or should I recalculate X and Y everytime I switch between behaviors, if yes how to do this, any sugestions, advices, opinions.
ltj
New User
 
Posts: 4
Joined: Thu Apr 24, 2008 7:01 pm

Return to RCX Software

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff