problems in navigation

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

Moderators: roger, gloomyandy, skoehler

hflores
New User
Posts: 14
Joined: Mon Feb 27, 2017 8:50 pm

problems in navigation

Postby hflores » Thu Aug 17, 2017 9:51 pm

I have problems in navigation. For example the following code performs the robot rotation.

Code: Select all

   void Giro(int grados, int left, int right)
   {
      int Div = 360 / grados;

      double k = 0.99;
      int angle=(int)Math.round((((16.7*Math.PI)/Div)/(6.88 * Math.PI))*360.0);
      angle = (int)(angle * k);
      mDerecho.resetTachoCount();// 2 RPM
      mIzquierdo.resetTachoCount();
       
       mDerecho.setSpeed(90);// 2 RPM
       mIzquierdo.setSpeed(90);
      
      // turn back
       mDerecho.synchronizeWith(new EV3LargeRegulatedMotor[] { mIzquierdo });
       
       mDerecho.startSynchronization();
       mDerecho.rotate(angle, true);
       mIzquierdo.rotate(angle * (-1), true);
       mDerecho.endSynchronization();
       
       mDerecho.waitComplete();
       mIzquierdo.waitComplete();      

   }

But there are times when the spin is done correctly and in others it does not get to spin correctly by increasing or decreasing the angle. This is mainly when the robot is turned off and on again.

What is the problem so you always miss the calculation?

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

Re: problems in navigation

Postby gloomyandy » Thu Aug 17, 2017 10:47 pm

I'm sorry but I have no idea what problem it is that you are describing. That code seems to make no sense at all to me, why do you have the magic numbers 16.7 and 6.88 in there? Why are you calculating some sort of angle and then multiplying it by 0.99? What is this code even supposed to do? What sort of values of grados are you supplying? What do you expect to happen? What actually happens? Why are you resetting the tacho counts? What are the motors doing before this code is called? Post a video of your robot when it does what you want (and provide the details of what inputs you are providing) and then do the same for when your robot does not do what you want.
leJOS news https://lejosnews.wordpress.com/

hflores
New User
Posts: 14
Joined: Mon Feb 27, 2017 8:50 pm

Re: problems in navigation

Postby hflores » Fri Aug 18, 2017 6:26 pm

Hi,

Wheel-to-wheel distance = 16.7 cm
Wheel diameter = 6.88
K constant = 0.99, Because I read in an article that is required to multiply by a constant. To rotate a defined angle

This video will take it first
https://www.dropbox.com/s/pddte16mpnqfu2r/VID_20170817_223957.mp4?dl=0

I'll take it later
https://www.dropbox.com/s/rqkzs1qceac91uj/VID_20170817_224104.mp4?dl=0

The code :

Code: Select all

      //the main() function
      //call to
      
          new Principal().Avanzar(); //PID Line Fallower

       motores.Giro(-115, 100, 100); // Rotate
               
       new Principal().GiroDerechoParaSensorIzquierdo(90, 90);


Code: Select all

   private void Avanzar()  throws Exception
   {
       int LightValue;
       int time = 0;
       
        while ((sensorDer.LuzValor() != sensorLinea.ObtenerNegro()))
        {    
           LightValue = sensorLinea.LuzValor();
        
           new Principal().CalcularPID(LightValue);
           motores.forward(powerIZQ, powerDER);
           Thread.sleep(dT);
           time++;                
        }
   }


Code: Select all

   void Giro(int grados, int left, int right)
   {
      int Div = 360 / grados;

      double k = 0.99;
      int angle=(int)Math.round((((16.7*Math.PI)/Div)/(6.88 * Math.PI))*360.0);
      angle = (int)(angle * k);
      mDerecho.resetTachoCount();// 2 RPM
      mIzquierdo.resetTachoCount();
       
       mDerecho.setSpeed(90);// 2 RPM
       mIzquierdo.setSpeed(90);
      
      // turn back
       mDerecho.synchronizeWith(new EV3LargeRegulatedMotor[] { mIzquierdo });
       
       mDerecho.startSynchronization();
       mDerecho.rotate(angle, true);
       mIzquierdo.rotate(angle * (-1), true);
       mDerecho.endSynchronization();
       
       mDerecho.waitComplete();
       mIzquierdo.waitComplete();      

   }   


Code: Select all

   private void GiroDerechoParaSensorIzquierdo(int leftPower, int rightPower)  throws Exception
   {
        while ((sensorIzq.LuzValor() != sensorIzq.ObtenerNegro()))
        {
           motores.GiroDerecho(leftPower, rightPower);
           Thread.sleep(dT);                
        }
        Thread.sleep(dT);
        while ((sensorIzq.LuzValor() != sensorIzq.ObtenerBlanco()))
        {
           motores.GiroDerecho(leftPower, rightPower);   
           Thread.sleep(dT);   
        }
   }


Please help me...
:-)

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

Re: problems in navigation

Postby gloomyandy » Fri Aug 18, 2017 8:13 pm

So what steps have you taken to debug your code? How do you know which parts of your code are being used to perform the turns? Looking at the video it seems to make the first turn as you would expect but in the second case it then seems to make an additional turn. I suspect that that is being caused by one of your sensor driven sections of code. But you need to add trace code to work out what is going on. You almost certainly need to be logging what values the sensors are returning. Remember senors are not perfect and will often return unexpected values, simply testing the return value once and then acting on it is almost always a bad idea.
leJOS news https://lejosnews.wordpress.com/

hflores
New User
Posts: 14
Joined: Mon Feb 27, 2017 8:50 pm

Re: problems in navigation

Postby hflores » Fri Aug 18, 2017 9:33 pm

So what steps have you taken to debug your code?

Check the values returned by the color sensor
In the black line returns 7, 13 and 2. On the white surface returns 6

How do you know which parts of your code are being used to perform the turns?

The following functions are used for the rotation

Code: Select all

   void Giro(int grados, int left, int right)
   {
      int Div = 360 / grados;

      double k = 0.99;
      int angle=(int)Math.round((((16.7*Math.PI)/Div)/(6.88 * Math.PI))*360.0);
      angle = (int)(angle * k);
      mDerecho.resetTachoCount();// 2 RPM
      mIzquierdo.resetTachoCount();
       
       mDerecho.setSpeed(90);// 2 RPM
       mIzquierdo.setSpeed(90);
      
      // turn back
       mDerecho.synchronizeWith(new EV3LargeRegulatedMotor[] { mIzquierdo });
       
       mDerecho.startSynchronization();
       mDerecho.rotate(angle, true);
       mIzquierdo.rotate(angle * (-1), true);
       mDerecho.endSynchronization();
       
       mDerecho.waitComplete();
       mIzquierdo.waitComplete();      

   }




Code: Select all

    public void GiroDerecho(int leftPower, int rightPower)
    {
       mDerecho.resetTachoCount();// 2 RPM
       mIzquierdo.resetTachoCount();
       
       mDerecho.setSpeed(rightPower);// 2 RPM
       mIzquierdo.setSpeed(leftPower);

       mDerecho.synchronizeWith(new EV3LargeRegulatedMotor[] { mIzquierdo });
       mDerecho.startSynchronization();
       mDerecho.backward();
       mIzquierdo.forward();
       mDerecho.endSynchronization();
       
    }



"Remember senors are not perfect and will often return unexpected values, simply testing the return value once and then acting on it is almost always a bad idea."

How can I correct the code so that this does not happen?

Are these instructions too many?
mDerecho.resetTachoCount();// 2 RPM
mIzquierdo.resetTachoCount();

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

Re: problems in navigation

Postby gloomyandy » Fri Aug 18, 2017 10:04 pm

No one is going to debug your code for you. You need to work out what is going on. You need to work out what parts of your code are causing the robot to rotate and why. Add code to your methods to log when they are being called, what sensor reading you are getting etc. Is this for some sort of school or collage project? If so you should talk with your teacher.

It is almost never a good idea to reset the tachometers why are you doing that?
leJOS news https://lejosnews.wordpress.com/

hflores
New User
Posts: 14
Joined: Mon Feb 27, 2017 8:50 pm

Re: problems in navigation

Postby hflores » Fri Aug 18, 2017 11:42 pm

I do not need you to debug my code, I thought I could help find the problem. I think this is the solution:

[url]
https://bricks.stackexchange.com/questi ... lowing-the
[/url]


Thanks.-

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

Re: problems in navigation

Postby gloomyandy » Sat Aug 19, 2017 7:25 am

I have been helping. I've been explaining to you what you need to do to debug what is going on. They are talking about a small movement as the robot starts, your video shows your robot making a huge extra turn. You need to spend some time understanding what is causing that movement. It may be a small difference in starting position but if that is the case then you have a problem with the way you detect when to make other turns. Your robot must be robust against small positional errors and sensor noise. Until you have code to allow you to understand exactly what your robot is doing and why you will just be making random guesses which may or may not resolve the problem.

Add code to your program to log when each method is called and when it exits. Add code to log when major decisions are made (such as detecting a turn point), add code to log the sensor readings. All of this information can be written to a file and the file uploaded to your PC for to you look at after a run. Video your run and you should be able to match the log file entries (make sure you include a timestamp against each one) against the video. That will allow you to understand exactly what is going on.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 4 guests