📄 cencoder.cpp
字号:
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
encoder->SetMaxPeriod(maxPeriod);
}
/**
* Determine if the encoder is stopped.
* Using the MaxPeriod value, a boolean is returned that is true if the encoder is considered
* stopped and false if it is still moving. A stopped encoder is one where the most recent pulse
* width exceeds the MaxPeriod.
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
* @return True if the encoder is considered stopped.
*/
bool GetEncoderStopped(UINT32 aChannel, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
return encoder->GetStopped();
else
return false;
}
/**
* Determine if the encoder is stopped.
* Using the MaxPeriod value, a boolean is returned that is true if the encoder is considered
* stopped and false if it is still moving. A stopped encoder is one where the most recent pulse
* width exceeds the MaxPeriod.
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
* @return True if the encoder is considered stopped.
*/
bool GetEncoderStopped(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
return encoder->GetStopped();
else
return false;
}
/**
* The last direction the encoder value changed.
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
* @return The last direction the encoder value changed.
*/
bool GetEncoderDirection(UINT32 aChannel, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
return encoder->GetDirection();
else
return false;
}
/**
* The last direction the encoder value changed.
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
* @return The last direction the encoder value changed.
*/
bool GetEncoderDirection(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
return encoder->GetDirection();
else
return false;
}
/**
* Get the distance the robot has driven since the last reset.
*
* @return The distance driven since the last reset as scaled by the value from SetEncoderDistancePerPulse().
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
double GetEncoderDistance(UINT32 aChannel, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
return encoder->GetDistance();
else
return 0.0;
}
/**
* Get the distance the robot has driven since the last reset.
*
* @return The distance driven since the last reset as scaled by the value from SetEncoderDistancePerPulse().
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
double GetEncoderDistance(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
return encoder->GetDistance();
else
return 0.0;
}
/**
* Get the current rate of the encoder.
* Units are distance per second as scaled by the value from SetEncoderDistancePerPulse().
*
* @return The current rate of the encoder.
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
double GetEncoderRate(UINT32 aChannel, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
return encoder->GetRate();
else
return 0.0;
}
/**
* Get the current rate of the encoder.
* Units are distance per second as scaled by the value from SetEncoderDistancePerPulse().
*
* @return The current rate of the encoder.
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
double GetEncoderRate(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
return encoder->GetRate();
else
return 0.0;
}
/**
* Set the minimum rate of the device before the hardware reports it stopped.
*
* @param minRate The minimum rate. The units are in distance per second as scaled by the value from SetEncoderDistancePerPulse().
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
void SetMinEncoderRate(UINT32 aChannel, UINT32 bChannel, double minRate)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
encoder->SetMinRate(minRate);
}
/**
* Set the minimum rate of the device before the hardware reports it stopped.
*
* @param minRate The minimum rate. The units are in distance per second as scaled by the value from SetEncoderDistancePerPulse().
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
void SetMinEncoderRate(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel, double minRate)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
encoder->SetMinRate(minRate);
}
/**
* Set the distance per pulse for this encoder.
* This sets the multiplier used to determine the distance driven based on the count value
* from the encoder.
* Do not include the decoding type in this scale. The library already compensates for the decoding type.
* Set this value based on the encoder's rated Pulses per Revolution and
* factor in gearing reductions following the encoder shaft.
* This distance can be in any units you like, linear or angular.
*
* @param distancePerPulse The scale factor that will be used to convert pulses to useful units.
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
void SetEncoderDistancePerPulse(UINT32 aChannel, UINT32 bChannel, double distancePerPulse)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
encoder->SetDistancePerPulse(distancePerPulse);
}
/**
* Set the distance per pulse for this encoder.
* This sets the multiplier used to determine the distance driven based on the count value
* from the encoder.
* Do not include the decoding type in this scale. The library already compensates for the decoding type.
* Set this value based on the encoder's rated Pulses per Revolution and
* factor in gearing reductions following the encoder shaft.
* This distance can be in any units you like, linear or angular.
*
* @param distancePerPulse The scale factor that will be used to convert pulses to useful units.
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
void SetEncoderDistancePerPulse(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel, double distancePerPulse)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
encoder->SetDistancePerPulse(distancePerPulse);
}
/**
* Set the direction sensing for this encoder.
* This sets the direction sensing on the encoder so that it could count in the correct
* software direction regardless of the mounting.
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
* @param reverseDirection true if the encoder direction should be reversed
*/
void SetEncoderReverseDirection(UINT32 aChannel, UINT32 bChannel, bool reverseDirection)
{
Encoder *encoder = AllocateEncoder(aChannel, bChannel);
if (encoder != NULL)
encoder->SetReverseDirection(reverseDirection);
}
/**
* Set the direction sensing for this encoder.
* This sets the direction sensing on the encoder so that it couldl count in the correct
* software direction regardless of the mounting.
*
* @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
* @param reverseDirection true if the encoder direction should be reversed
*/
void SetEncoderReverseDirection(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel, bool reverseDirection)
{
Encoder *encoder = AllocateEncoder(aSlot, aChannel, bSlot, bChannel);
if (encoder != NULL)
encoder->SetReverseDirection(reverseDirection);
}
/**
* Free the resources associated with this encoder.
* Delete the Encoder object and the entries from the cache for this encoder.
* * @param aSlot The digital module slot for the A Channel on the encoder
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bSlot The digital module slot for the B Channel on the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
void DeleteEncoder(UINT32 aSlot, UINT32 aChannel, UINT32 bSlot, UINT32 bChannel)
{
if (SensorBase::CheckDigitalModule(aSlot) && SensorBase::CheckDigitalChannel(aChannel))
{
delete encoders[DigitalModule::SlotToIndex(aSlot)][aChannel - 1];
encoders[DigitalModule::SlotToIndex(aSlot)][aChannel - 1] = NULL;
}
}
/**
* Free the resources associated with this encoder.
* Delete the Encoder object and the entries from the cache for this encoder.
*
* @param aChannel The channel on the digital module for the A Channel of the encoder
* @param bChannel The channel on the digital module for the B Channel of the encoder
*/
void DeleteEncoder(UINT32 aChannel, UINT32 bChannel)
{
DeleteEncoder(SensorBase::GetDefaultDigitalModule(), aChannel, SensorBase::GetDefaultDigitalModule(), bChannel);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -