Log in

View Full Version : AnalogChannel as both an accumulator AND a normal input?


Jared Russell
28-01-2009, 21:52
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
You should be able to do this. The Gyro class has a constructor that accepts an existing AnalogChannel object.


/**
* 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.


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
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.


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.


return m_voltsPerDegreePerSecond*m_analog->GetVoltage();