Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 718127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:29:29+00:00 2026-05-14T05:29:29+00:00

Here is my code: /* Scott Landau Robot Lab Assignment 1 */ // Standard

  • 0

Here is my code:

/*
Scott Landau
Robot Lab Assignment 1
*/    

// Standard Java Libs

import java.io.*;

// Player/Stage Libs

import javaclient2.*;
import javaclient2.structures.*;
import javaclient2.structures.sonar.*;

// Begin

public class SpinningRobot

{
    public static Position2DInterface pos = null;
    public static LaserInterface laser = null;

    public static void main(String[] args)
    {
        PlayerClient robot = new PlayerClient("localhost", 6665);
        laser = robot.requestInterfaceLaser(0, PlayerConstants.PLAYER_OPEN_MODE);
        pos = robot.requestInterfacePosition2D(0,PlayerConstants.PLAYER_OPEN_MODE);

        robot.runThreaded (-1, -1);

        pos.setSpeed(0.5f, -0.25f);

        // end pos
        float x, y;
        x = 46.0f;
        y = -46.0f;

        boolean done = false;

        while( !done ){

            if(laser.isDataReady()) { 

                float[] laser_data = laser.getData().getRanges();

                System.out.println("== IR Sensor ==");
                System.out.println("Left Wall Distance: "+laser_data[360]);
                System.out.println("Right Wall Distance: " +laser_data[0]);

                // if laser doesn't reach left wall, move to detect it
                // so we can guide using left wall
                if ( laser_data[360] < 0.6f ) {
                    while ( laser_data[360] < 0.6f ) {

                        pos.setSpeed(0.5f, -0.5f);
                    }
            } else if ( laser_data[0] < 0.6f ) {
                                                                                                   while(laser_data[0<0.6f)                                       {                                    pos.setSpeed(0.5f, 0.5f);
                                   }
            }
                pos.setSpeed(0.5f, -0.25f);



// end pos?
done = ( (pos.getX() == x) && (pos.getY() == y) );  
            }

        }

    }





} // End

I was trying to have the Roomba go continuously at a slight right curve, quickly turning away from each wall it came to close to if it recognized it with it’s laser. I can only use laser_data[360] and laser_data[0] for this one robot. I think this would eventually navigate the maze.

However, I am using the Player Stage platform, and Stage freezes when the Roomba comes close to a wall using this code, I have no idea why.

Also, if you can think of a better maze navigation algorithm, please let me know.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:29:29+00:00Added an answer on May 14, 2026 at 5:29 am

    It seems like you get stuck against a wall because you are oscillating around distance 0.6.

    For instance:

    1. Drive angling toward wall, eventually reaching < 0.6f
    2. Rotate away from wall, stop when > 0.6f. In other words 0.6000001f (for instance)
    3. Resume normal trajectory.
    4. Almost immediately < 0.6f
    5. Goto 2

    You will get stuck angling slightly toward and slightly away from the wall.

    You need a buffer zone. Once you get within MIN_DIS distance from the wall you need to rotate away until you reach some BUFFER_DIS from the wall where BUFFER_DIS > MIN_DIS by a fair amount.

    EDIT:

    Looks like you have a few issues. First you are checking if the laser_data is close to a wall, and if it is you are rotating toward the wall. You need to check if it is NOT close to a wall, and rotate toward it.

    Second, you are in a very tight while loop, adjusting wheel speeds. This will probably result in bad things. You need to call a trackWall() function when you are too far from the wall, which will poll laser.isDataReady() in a separate loop. Either that, or you need a state-machine in your main polling loop. If not, you are pointlessly adjusting wheel speed with stale laser data.

    Third, can you guarantee that the wall will always be within 0.6f? If not, your robot will spin infinitely if it gets to far from the wall.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.