View Single Post
  #2   Spotlight this post!  
Unread 04-03-2010, 15:36
AmoryG AmoryG is offline
Registered User
FRC #2423 (KwarQs)
Team Role: Alumni
 
Join Date: Mar 2008
Rookie Year: 2008
Location: Watertown, MA
Posts: 221
AmoryG has much to be proud ofAmoryG has much to be proud ofAmoryG has much to be proud ofAmoryG has much to be proud ofAmoryG has much to be proud ofAmoryG has much to be proud ofAmoryG has much to be proud ofAmoryG has much to be proud of
Re: Using one gyro sensor as two viritual gyros in code

Quote:
Originally Posted by DavidGitz View Post
I agree with this statement, generally. However, due to the time limitations through the FRC competition and (probably) lack of a testing environment right now, and not much time available at the regionals, and coupled with the errors they've already recieved, unless a very simple programming approach could be used (i.e. open up 2 references to the same device) I would go through the hardware branch. I'm sure the right way of doing this would be fairly easy, but with lack of a testing environment I would rather have *definitely* be right the first time than have to debug code. Like most things, it is a tradeoff. It wouldn't be the best solution, but might be the most reliable.
Quote:
Originally Posted by Bongle View Post
You could make a class of your own that holds a pointer to your original gyro class. It could have a reset function that takes note of the current absolute heading, and a getangle function which returns your difference since the last time you reset.
Code:
class RelativeGyro
{
public:
  RelativeGyro(Gyro* pAbsoluteGyro) : m_pGyro(pAbsoluteGyro), m_dBaseAngle(0.0)
  {
  }

  void Reset()
  {
    m_dBaseAngle = m_pGyro->GetAngle();
  }
  double GetAngle()
  {
    return m_pGyro->GetAngle() - m_dBaseAngle;
  }
private:
  double m_dBaseAngle;
  Gyro* m_pGyro;
}
An advantage of this design is that you could actually create multiple RelativeGyro classes within your robot, if that is what you want. You could have one for shooting, one for target-finding, etc.

If you're not using C++, you'll have to adapt my idea to LabView or Java if you like it.
The above code really is as simple as it gets (that is, if you understand what the code does). If you were to use something like this, all you would need to do is create a RelativeGyro and feed its constructor a pointer or reference to a gyro object:

Gyro gyro(1);

RelativeGyro relativegyro(&gyro);

Then use Reset and GetAngle as you would with any gyro.
__________________
KwarQs 2423

2008 Boston Regional Rookie Allstars

http://whsrobot.blogspot.com/