View unanswered posts | View active topics It is currently Sat Nov 01, 2014 12:49 am






Reply to topic  [ 5 posts ] 
Odd glitch? 
Author Message
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Odd glitch?
So in my continued endeavor to produce a working navigating robot in a limited timeframe, I have hit upon a bug in my code. I'm using motor encoders to supplement my GPS readings, but there's an odd problem. When I initialize the coordinates to the GPS position, the coordinates aren't moving up with the encoders. However, when I leave the coordinates at their initial value of 0, it increments them correctly. I have no idea why, so I'd appreciate a look at my code to see what I messed up. :oops:

Code:
#pragma config(Sensor, S1,     DGPS,           sensorI2CCustom)
#pragma config(Sensor, S4,     HTMC,           sensorI2CCustom)
#pragma config(Motor,  motorA,           ,             tmotorNXT, openLoop, reversed, encoder)
#pragma config(Motor,  motorB,           ,             tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//20 inches of movement per motor rotation

#include "C:\Program Files (x86)\Robomatter Inc\ROBOTC Development Environment\Sample Programs\NXT\3rd Party Sensor Drivers\drivers\dexterind-gps.h"
#include "C:\Program Files (x86)\Robomatter Inc\ROBOTC Development Environment\Sample Programs\NXT\3rd Party Sensor Drivers\drivers\hitechnic-compass.h"

//Test Latitude = 42.000389
//Test Longitude = -88.038040
//Longitude = x axis
//Latitude = y axis
//Smallest unit that GPS can measure equals roughly 5.282321853711464 inches.

task main()
{
   float latitude = 0;
   float Longitude = 0;

   int heading;
   wait1Msec(1000);

   while(nNxtButtonPressed != kEnterButton)
   {
      nxtDisplayCenteredTextLine(3, "%f", (float)DGPSreadLatitude(DGPS) / 1000000);
      nxtDisplayCenteredTextLine(4, "%f", (float)DGPSreadLongitude(DGPS) / 1000000);
      wait1Msec(500);
   }

   //float TarLong = (float)DGPSreadLongitude(DGPS) / 1000000;
   //float TarLat = (float)DGPSreadLatitude(DGPS) / 1000000;

   float TarLong = -88.038040;
   float TarLat = 42.000389;

   DGPSsetDestination(DGPS, TarLat, TarLong);

   time1[T1] = 0;

   nMotorEncoder[motorA] = 0;
   nMotorEncoder[motorB] = 0;
   nMotorEncoder[motorC] = 0;
   
   wait1Msec(1000);
   
   Longitude = (float)DGPSreadLongitude(DGPS) / 1000000;
   latitude = (float)DGPSreadLatitude(DGPS) / 1000000;

   while(true)
   {

      /*if(time1[T1] > 500)
      {
         Longitude = Longitude - (Longitude - ((float)DGPSreadLongitude(DGPS) / 1000000));
         latitude = (float)DGPSreadLatitude(DGPS) / 1000000;
         time1[T1] = 0;
      }*/

      if(Longitude > TarLong + 0.00001) HTMCsetTarget(HTMC, 270);
      else if(Longitude < TarLong - 0.00001) HTMCsetTarget(HTMC, 90);
      else if(Longitude > TarLong - 0.00001 && Longitude < TarLong + 0.00001) StopAllTasks();
      //if(Latitude > TarLat + 0.000025) HTMCsetTarget(HTMC, 180);
      //else if(Latitude < TarLat - 0.000025) HTMCsetTarget(HTMC, 0);
      //else if(Longitude > TarLong - 0.00001 && Longitude < TarLong + 0.00001  && Latitude > TarLat - 0.00001 && Latitude < TarLat + 0.00001) StopAllTasks();

      float compass = HTMCreadRelativeHeading(HTMC);

      nxtDisplayCenteredTextLine(0, "TLon: %f", TarLong);
      nxtDisplayCenteredTextLine(1, "TLat: %f", TarLat);
      nxtDisplayCenteredTextLine(2, "Lon: %f", Longitude);
      nxtDisplayCenteredTextLine(3, "Lat: %f", latitude);
      nxtDisplayCenteredTextLine(4, "Rel Comp: %d", compass);
      nxtDisplayCenteredTextLine(5, "Act Comp: %d", HTMCreadHeading(HTMC));
      nxtDisplayCenteredTextLine(6, "En: %d", nMotorEncoder[motorA]);

      float bPwr = 100 - (compass * 2);
      float cPwr = 100 + (compass * 2);

      if(bPwr < 50) motor[motorB] = 50;
      else motor[motorB] = bPwr;
      if(cPwr < 50) motor[motorC] = 50;
      else motor[motorC] = cPwr;
      motor[motorA] = (motorPWMLevel[motorB] + motorPWMLevel[motorC]) / 2;

      //if((nMotorEncoder[motorA] + nMotorEncoder[motorB] + nMotorEncoder[motorC]) / 3 = 95)
      if(nMotorEncoder[motorA] >= 95)
      {
         if(compass > 10 && compass < 170) Longitude = Longitude + (float)0.000001;
         else Longitude = Longitude - (float)0.000001;

         nMotorEncoder[motorA] = 0;
      }
   }
}


It's in early stages right now, so it's pretty messy.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Mon Jul 22, 2013 9:00 pm
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Odd glitch?
It seems that it will not increment the value unless it's at zero before the loop starts... Very odd, I cannot seem to find a reason for this, or a way to fix it...

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Tue Jul 23, 2013 9:02 pm
Profile WWW
Rookie
User avatar

Joined: Wed Dec 01, 2010 5:15 pm
Posts: 31
Post Re: Odd glitch?
Take a look here: http://www.robotc.net/wiki/Data_Types. When you have your lat/long as partially integers, you cannot subtract such a small number and have the result fit in a float, so you end up with the same number you started with.


Wed Jul 24, 2013 8:38 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Odd glitch?
Okay, I still don't really see why it doesn't work, but I guess I'll just figure out another way.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed Jul 24, 2013 8:50 am
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Odd glitch?
I think what maths222 is trying to say is, your float isn't that accurate (you should use a double but RobotC doesn't have one), so when you cast it back and forth, nothing happens.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Wed Jul 24, 2013 7:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.