Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   AnalogChannel as both an accumulator AND a normal input? (http://www.chiefdelphi.com/forums/showthread.php?t=73152)

Jared Russell 28-01-2009 21:52

AnalogChannel as both an accumulator AND a normal input?
 
Can this be done?

In other words, the Gyro class uses an accumulator channel and does not give me a public method to get the instantaneous reading from the sensor. Is this because an input can be either an instantaneous read OR an accumulator, or is it just a WPILib design issue?

Thanks!

MattD 29-01-2009 02:29

Re: AnalogChannel as both an accumulator AND a normal input?
 
You should be able to do this. The Gyro class has a constructor that accepts an existing AnalogChannel object.

Code:

/**
 * Gyro constructor with a precreated analog channel object.
 * Use this constructor when the analog channel needs to be shared. There
 * is no reference counting when an AnalogChannel is passed to the gyro.
 * @param channel The AnalogChannel object that the gyro is connected to.
 */
Gyro::Gyro(AnalogChannel *channel)

You can create an AnalogChannel and use the standard methods on it, while using the accumulator information via the Gyro class at the same time.

Code:

AnalogChannel *channel = new AnalogChannel(1);
Gyro *gyro = new Gyro(channel);

float value = channel->GetVoltage();
float angle = gyro->GetAngle();

Alternatively, you could modify the Gyro class to provide access to this information.

jbobj 31-01-2009 10:14

Re: AnalogChannel as both an accumulator AND a normal input?
 
Quote:

Originally Posted by MattD (Post 810219)
You can create an AnalogChannel and use the standard methods on it, while using the accumulator information via the Gyro class at the same time.

Code:

AnalogChannel *channel = new AnalogChannel(1);
Gyro *gyro = new Gyro(channel);

float value = channel->GetVoltage();
float angle = gyro->GetAngle();

Alternatively, you could modify the Gyro class to provide access to this information.

If this is so, and I want to get the Degrees per Second from the Gyro, does this line of code within the Gyro class do that? m_analog is the AnalogChannel within the Gyro class, and voltsPerDegreePerSecond is a constant I see in there.

Code:

return m_voltsPerDegreePerSecond*m_analog->GetVoltage();


All times are GMT -5. The time now is 02:31.

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