Go to Post Thanks for giving up your holiday for Science! - Foster [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-03-2010, 20:13
lollypop2020 lollypop2020 is offline
Registered User
FRC #2733 (Pigmice)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2003
Location: Portland, OR
Posts: 19
lollypop2020 is an unknown quantity at this point
Using one gyro sensor as two viritual gyros in code

For our code, we need to have the equavalent of two gyros. One of them is used by the driver and by the aiming software and is reset quite frequently. The other one is for the robot's true heading (with error of course), and should not ever be reset. I tried opening two gyro references using the same AI channel, and using each reference respectively where it was needed but I got errors on the DS for trying to use an already allocated AI channel. Is there a way to get around this without keeping track of the angle of the gyro manually? I know I could probably write my own code to have two independant counters that could be used seperately, but I would rather not have to do that, however I will if it's the only option. Could I use a PWM splitter cable and plug one gyro into two AI ports? Or is there anything else I could do?
__________________
  #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.
  #3   Spotlight this post!  
Unread 04-03-2010, 08:39
DavidGitz's Avatar
DavidGitz DavidGitz is offline
Lead Technical Advisor
FRC #1208 (MeTool Brigade)
Team Role: Coach
 
Join Date: Dec 2006
Rookie Year: 1996
Location: O'Fallon, IL
Posts: 341
DavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud of
Send a message via AIM to DavidGitz Send a message via MSN to DavidGitz Send a message via Yahoo to DavidGitz
Re: Using one gyro sensor as two viritual gyros in code

That's a good idea about using a PWM Y Cable. That would be by far the easiest option I think.
__________________
  #4   Spotlight this post!  
Unread 04-03-2010, 09:56
Russ Beavis Russ Beavis is offline
Registered User
no team
 
Join Date: Nov 2005
Location: Manchester, NH - DEKA R&D Corp.
Posts: 341
Russ Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond reputeRuss Beavis has a reputation beyond repute
Re: Using one gyro sensor as two viritual gyros in code

There's no reason why your program can't store the data that you need in separate variables. Aren't there "user data" parameters that can be sent to the Driver Station in addition to the "direct" low-level analog and digital input readings? You should not need to resort to a hardware solution for what is essentially storing a single analog reading in 2 memory locations.

Russ
  #5   Spotlight this post!  
Unread 04-03-2010, 12:22
DavidGitz's Avatar
DavidGitz DavidGitz is offline
Lead Technical Advisor
FRC #1208 (MeTool Brigade)
Team Role: Coach
 
Join Date: Dec 2006
Rookie Year: 1996
Location: O'Fallon, IL
Posts: 341
DavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud ofDavidGitz has much to be proud of
Send a message via AIM to DavidGitz Send a message via MSN to DavidGitz Send a message via Yahoo to DavidGitz
Re: Using one gyro sensor as two viritual gyros in code

Quote:
Originally Posted by Russ Beavis View Post
There's no reason why your program can't store the data that you need in separate variables. Aren't there "user data" parameters that can be sent to the Driver Station in addition to the "direct" low-level analog and digital input readings? You should not need to resort to a hardware solution for what is essentially storing a single analog reading in 2 memory locations.

Russ
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.
__________________
  #6   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/
  #7   Spotlight this post!  
Unread 05-03-2010, 01:49
lollypop2020 lollypop2020 is offline
Registered User
FRC #2733 (Pigmice)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2003
Location: Portland, OR
Posts: 19
lollypop2020 is an unknown quantity at this point
Re: Using one gyro sensor as two viritual gyros in code

Thanks for all the help! I think I'll probably go with the hardware approach and try to make a PWM splitter before our first match tomorrow. If it doesn't work for some reason, that code doesn't look too bad. I must agree with DavidGitz though, time for debugging is something we do not have, and at the moment, this just seems easier.
__________________
  #8   Spotlight this post!  
Unread 05-03-2010, 13:59
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,086
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Using one gyro sensor as two viritual gyros in code

Quote:
Originally Posted by lollypop2020 View Post
Thanks for all the help! I think I'll probably go with the hardware approach and try to make a PWM splitter before our first match tomorrow. If it doesn't work for some reason, that code doesn't look too bad. I must agree with DavidGitz though, time for debugging is something we do not have, and at the moment, this just seems easier.
I wouldn't recommend doing it the hardware way. One thing to keep in mind is that the gyro requires the use of an accumulator channel, so you have to use channels that support that (I think the first two channels support it, on the first analog module only). Additionally, you might get some odd effects by connecting two channels together that way. If they accumulate different values, then each of your gyros is going to be offset from the other, and that could cause issues as well.

The software is trivial, do it that way. The code by Bongle looks like it should work as is without any debugging.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #9   Spotlight this post!  
Unread 05-03-2010, 14:09
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: Using one gyro sensor as two viritual gyros in code

Quote:
Originally Posted by virtuald View Post
...
I wish to join the dead horse beaters in this thread. The Y-cable is the cheap fix that will almost definitely bite you later. Spend the extra 10 minutes and do it right.
  #10   Spotlight this post!  
Unread 07-03-2010, 22:29
ideasrule's Avatar
ideasrule ideasrule is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Toronto
Posts: 108
ideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the rough
Re: Using one gyro sensor as two viritual gyros in code

Quote:
Originally Posted by EricVanWyk View Post
I wish to join the dead horse beaters in this thread. The Y-cable is the cheap fix that will almost definitely bite you later. Spend the extra 10 minutes and do it right.
That horse never listened to me, so I'll join the club. This code is so simple that it shouldn't require any testing to get right. The people who made the gyro weren't expecting the analog module to draw twice as much current as necessary from the gyro, so if you use the Y-cable approach, you'd be going against what the engineers designed the gyro for. Not a good idea!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CODE: Using the gyro in autonomous Kingofl337 Programming 1 20-01-2008 19:11
two gyros? gmiller_1249 Programming 7 24-05-2007 03:23
problems using gyro/adc code with camera default code tanstaafl Programming 7 22-01-2006 23:09
Code violation using Hall effect sensor pickle Programming 9 19-01-2005 00:10
Using two spikes for one motor supergrover Control System 6 24-02-2004 15:36


All times are GMT -5. The time now is 23:25.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi