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

  • SEARCH
  • Home
  • 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 7077819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:28:13+00:00 2026-05-28T06:28:13+00:00

Background (can skip to question below…) Currently working with a lego Mindstorm robot and

  • 0

Background (can skip to question below…)

Currently working with a lego Mindstorm robot and the icommand API (http://lejos.sourceforge.net/p_technologies/nxt/icommand/api/index.html).

Having some trouble with one of the motor control methods. The methods rotates the motor by a given angle:

Motor.A.rotateTo(target);

This function will not return until the motor has completed the movement. This is fine, but sometimes the motor fails to stop and will continue indefinitely thus stopping the program.

Question

Is there anyway I can make so the program waits for up n seconds for the method Motor.A.rotateTo(target); to return. And then if it has not returned in that time, then call the method again. (If that could be looped until it is successful that would be even better.)

Thanks for reading, any help would be much appreciated.

Regards,
Joe

edit: corrected from Motor.A.rotate(target); to Motor.A.rotateTo(target);

  • 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-28T06:28:14+00:00Added an answer on May 28, 2026 at 6:28 am

    You can use ExecutorService or other threading solution to run rotate in a separate thread and wait for results. Here is a complete program that also retries given number of times:

    public static void main(String[] args) throws TimeoutException {
        final ExecutorService pool = Executors.newFixedThreadPool(10);
        runWithRetry(pool, 5);  //run here
    }
    
    public static void runWithRetry(final ExecutorService pool, final int retries) throws TimeoutException {
            final Future<?> result = pool.submit(new Runnable() {
                @Override
                public void run() {
                    Motor.A.rotate(angle);
                }
            });
            try {
                result.get(1, TimeUnit.SECONDS);  //wait here
            } catch (InterruptedException e) {
                throw new RuntimeException(e.getCause());
            } catch (ExecutionException e) {
                throw new RuntimeException(e.getCause());
            } catch (TimeoutException e) {
                if (retries > 1) {
                    runWithRetry(pool, retries - 1);  //retry here
                } else {
                    throw e;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background - I can get HttpListener working fine for HTTP traffic. I'm having trouble
You can skip to the bottom line if you don't care about the background:
I'm trying to thread this below function so that the background form can continue
The following is some background info on this post. You can just skip to
I'm designing a site with a fixed repeated background but can't work out why
The background-position property can be set in a variety of ways such as top
I have a background worker which can be cancelled. The normal flows interrupt itself
I come from a C++ background where I can use template mixins to write
I am drawing a quad as a background so I can apply a gradient.
How can I set the background color of an HTML element using css in

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.