problem with implement a behavior kick blue ball

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

problem with implement a behavior kick blue ball

Postby Faiz555 » Sat Nov 20, 2010 2:05 pm

I wrote already but not sucess.
I wish to use color sensor to detect a blue ball and motor B to kick the blue ball
Code: Select all
class DetectBall implements Behavior
{
  public DetectBall()
  {
    color = new ColorSensor(SensorPort.S1);
    sonar = new UltrasonicSensor(SensorPort.S3);
  }

  public boolean takeControl()
  {
    sonar.ping();
    return sonar.getDistance() < 5 && color.getColorNumber()==3;
  }

  public void suppress()
  {
   Motor.B.stop();
  }

  public void action()
  {
     Motor.B.rotate(-135); //start Motor.B rotating backward to kick ball
     Motor.B.stop();
     Motor.B.rotate(135); //rotate back to before 
  }
  private ColorSensor color;
  private UltrasonicSensor sonar;
}
Faiz555
New User
 
Posts: 16
Joined: Wed Sep 15, 2010 1:52 pm

Postby gloomyandy » Sat Nov 20, 2010 7:14 pm

If you want help you probably need to tell us more about what you have done so far. So for instance...
1. What happens when you run your code?
2. Have you checked that the Ultrasonic sensor can actually detect the ball when it is close enough for the color sensor to identify the color?
3. Have you checked that the color sensor will correctly identify the color when it is at a distance that the ultrasonic sensor sees as 5 units?
4. Have you tested your kick action to make sure it works?

No-one can write your program for you and I doubt if anyone will have the time to build a robot that is the same as yours to test your code. Eveyone has their own projects and will be busy, so to get help you need to make it easy for people to help you...

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

Postby Faiz555 » Sun Nov 21, 2010 6:43 am

gloomyandy wrote:If you want help you probably need to tell us more about what you have done so far. So for instance...
1. What happens when you run your code?
Nothing happen
2. Have you checked that the Ultrasonic sensor can actually detect the ball when it is close enough for the color sensor to identify the color?
yes
3. Have you checked that the color sensor will correctly identify the color when it is at a distance that the ultrasonic sensor sees as 5 units?
yes
4. Have you tested your kick action to make sure it works?
I tested motor. It works.
No-one can write your program for you and I doubt if anyone will have the time to build a robot that is the same as yours to test your code. Eveyone has their own projects and will be busy, so to get help you need to make it easy for people to help you...
Andy

I am not asking anyone to do it for me. I just want to know how to be work. Just want someone to help. Is it something wrong in the code?
Faiz555
New User
 
Posts: 16
Joined: Wed Sep 15, 2010 1:52 pm

Postby gloomyandy » Sun Nov 21, 2010 12:42 pm

So you still have not told us what you have done to work out what is going wrong... Also just providing single word answers does not really help or make your problem very interesting to other people, if people are not interested they will not want to try and help you.

How have you checked that the Ultrasonic sensor works at distances of 5cm and less? How reliable are the results? Most people find that the Ultrasonic sensor does not work reliably at such short distances...

How have you checked that the color sensor works correctly at these distances. Again most people find that the color sensor is not reliable at distances greater than a couple of cm... Have you tried the sensor in different light conditions? Does it always work?

How are you testing your code? I assume there is more than just the lines you have posted here?

There is nothing obviously wrong with the code you have posted, so you need to investigate further....

So have you tried adding code into your program to find out what is going on? Try adding some display statements into your takeControl method, is it even being called? If it is being called, what values are returned by the Ultrasonic sensor?, what values are being returned by the color sensor?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3893
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff