View Single Post
  #2   Spotlight this post!  
Unread 03-03-2010, 20:57
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Using one gyro sensor as two viritual gyros in code

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.