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 601819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:45:23+00:00 2026-05-13T16:45:23+00:00

i’m using a glutTimerFunc(…) to achieve motion of robot arm, my problem is left

  • 0

i’m using a glutTimerFunc(…) to achieve motion of robot arm, my problem is left side 0 degree to 90 is easily done,

when i try 0 to -90 degree, the arm is not stoping? i tried various methods, but all falied, can you suggest better options?

here’s my timer function,

void myTimerFunc(int var)
{
switch(var)
{
case 1: if(shoulder>=90)
            stop=1;

    if(!stop)
    {    
        shoulder = (shoulder + 5);
        glutPostRedisplay();
        glutTimerFunc(100,myTimerFunc,1);
        break;
    }


    if(shoulder<=0)
        stop1=1;

    if(!stop1)
    {
        shoulder = (shoulder - 5);
        glutPostRedisplay();
        glutTimerFunc(100,myTimerFunc,1);
        break;
    }

case 2: if(shoulder>=360)

        stop2=1;

    if(!stop2)

    {

        shoulder = (shoulder - 5);

        glutPostRedisplay();

        glutTimerFunc(100,myTimerFunc,2);

        break;

    }

// here robot arm is not stopping...........

if(shoulder<=270)
        stop2 = 0;
        stop3 = 1;



    if(!stop3)

    {

        shoulder = (shoulder + 5);

        glutPostRedisplay();

        glutTimerFunc(100,myTimerFunc,2);

        break;

    }

default:break;
}
}

i’m calling this from keyboard function…….

void keyboard (unsigned char key, int x, int y)
{
   switch (key) 
   {
      case 's':             
        glutTimerFunc(100,myTimerFunc,1);
            break;

        glutTimerFunc(100,myTimerFunc,2);
             break; 
  • 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-13T16:45:23+00:00Added an answer on May 13, 2026 at 4:45 pm

    Looks to me like you’re confused about how to treat angles. Are you using a [0, 360] scale for a full circle or [-180, +180]? I see a check against 270 in your code, but your prose mentions -90. Yes, they’re “the same”, but if it’s not working perhaps some confusion has crept into your code.

    If you’re going with [-180, +180], with zero degrees as the neutral position for your robot arm, perhaps you can take advantage of symmetry and use the absolute value function. You only have to code it once that way. If it’s successful for [0, +90] it’ll also work for [-90, 0] as well.

    It also seems to me that you’re not taking advantage of object-oriented thinking. This method has motion and timing and graphical refresh all in the same method. Writing smaller methods and unit testing each one to be sure that it works is a better approach. It’s called “decomposition”. The moment you say “it’s a big method”, it suggests to me that perhaps it’s too big and needs to be refactored.

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

Sidebar

Related Questions

No related questions found

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.