|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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;
}
If you're not using C++, you'll have to adapt my idea to LabView or Java if you like it. |
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Re: Using one gyro sensor as two viritual gyros in code
Quote:
|
|
#6
|
|||
|
|||
|
Re: Using one gyro sensor as two viritual gyros in code
Quote:
Quote:
Gyro gyro(1); RelativeGyro relativegyro(&gyro); Then use Reset and GetAngle as you would with any gyro. |
|
#7
|
|||
|
|||
|
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
|
||||
|
||||
|
Re: Using one gyro sensor as two viritual gyros in code
Quote:
The software is trivial, do it that way. The code by Bongle looks like it should work as is without any debugging. |
|
#9
|
|||
|
|||
|
Re: Using one gyro sensor as two viritual gyros in code
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
|
||||
|
||||
|
Re: Using one gyro sensor as two viritual gyros in code
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!
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |