本文整理汇总了C++中wpi_setWPIError函数的典型用法代码示例。如果您正苦于以下问题:C++ wpi_setWPIError函数的具体用法?C++ wpi_setWPIError怎么用?C++ wpi_setWPIError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpi_setWPIError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wpi_setWPIError
/**
* Get the value of the axis on a joystick.
* This depends on the mapping of the joystick connected to the specified port.
*
* @param stick The joystick to read.
* @param axis The analog axis value to read from the joystick.
* @return The value of the axis on the joystick.
*/
float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis)
{
if (stick >= kJoystickPorts)
{
wpi_setWPIError(BadJoystickIndex);
return 0;
}
if (axis >= m_joystickAxes[stick].count)
{
if (axis >= kMaxJoystickAxes)
wpi_setWPIError(BadJoystickAxis);
else
ReportJoystickUnpluggedError("WARNING: Joystick Axis missing, check if all controllers are plugged in\n");
return 0.0f;
}
int8_t value = m_joystickAxes[stick].axes[axis];
if(value < 0)
{
return value / 128.0f;
}
else
{
return value / 127.0f;
}
}
示例2: m_i2c
/**
* Constructor.
*
* @param moduleNumber The digital module that the sensor is plugged into (1 or 2).
*/
HiTechnicColorSensor::HiTechnicColorSensor(UINT8 moduleNumber)
: m_i2c (NULL)
{
m_table = NULL;
DigitalModule *module = DigitalModule::GetInstance(moduleNumber);
m_mode = kActive;
if (module)
{
m_i2c = module->GetI2C(kAddress);
// Verify Sensor
const UINT8 kExpectedManufacturer[] = "HiTechnc";
const UINT8 kExpectedSensorType[] = "ColorPD ";
if ( ! m_i2c->VerifySensor(kManufacturerBaseRegister, kManufacturerSize, kExpectedManufacturer) )
{
wpi_setWPIError(CompassManufacturerError);
return;
}
if ( ! m_i2c->VerifySensor(kSensorTypeBaseRegister, kSensorTypeSize, kExpectedSensorType) )
{
wpi_setWPIError(CompassTypeError);
}
nUsageReporting::report(nUsageReporting::kResourceType_HiTechnicColorSensor, moduleNumber - 1);
}
}
示例3: sync
/**
* Free an allocated resource.
* After a resource is no longer needed, for example a destructor is called for
* a channel assignment
* class, Free will release the resource value so it can be reused somewhere
* else in the program.
*/
void Resource::Free(uint32_t index) {
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
if (index == std::numeric_limits<uint32_t>::max()) return;
if (index >= m_isAllocated.size()) {
wpi_setWPIError(NotAllocated);
return;
}
if (!m_isAllocated[index]) {
wpi_setWPIError(NotAllocated);
return;
}
m_isAllocated[index] = false;
}
示例4: switch
/**
* Set the relay state.
*
* Valid values depend on which directions of the relay are controlled by the
* object.
*
* When set to kBothDirections, the relay can be any of the four states:
* 0v-0v, 0v-12v, 12v-0v, 12v-12v
*
* When set to kForwardOnly or kReverseOnly, you can specify the constant for
* the direction or you can simply specify kOff and kOn. Using only kOff and
* kOn is recommended.
*
* @param value The state to set the relay.
*/
void Relay::Set(Relay::Value value) {
if (StatusIsFatal()) return;
int32_t status = 0;
switch (value) {
case kOff:
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
HAL_SetRelay(m_forwardHandle, false, &status);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
HAL_SetRelay(m_reverseHandle, false, &status);
}
break;
case kOn:
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
HAL_SetRelay(m_forwardHandle, true, &status);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
HAL_SetRelay(m_reverseHandle, true, &status);
}
break;
case kForward:
if (m_direction == kReverseOnly) {
wpi_setWPIError(IncompatibleMode);
break;
}
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
HAL_SetRelay(m_forwardHandle, true, &status);
}
if (m_direction == kBothDirections) {
HAL_SetRelay(m_reverseHandle, false, &status);
}
break;
case kReverse:
if (m_direction == kForwardOnly) {
wpi_setWPIError(IncompatibleMode);
break;
}
if (m_direction == kBothDirections) {
HAL_SetRelay(m_forwardHandle, false, &status);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
HAL_SetRelay(m_reverseHandle, true, &status);
}
break;
}
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
示例5: switch
/**
* Set the relay state.
*
* Valid values depend on which directions of the relay are controlled by the
* object.
*
* When set to kBothDirections, the relay can be any of the four states:
* 0v-0v, 0v-12v, 12v-0v, 12v-12v
*
* When set to kForwardOnly or kReverseOnly, you can specify the constant for
* the
* direction or you can simply specify kOff and kOn. Using only kOff and
* kOn is
* recommended.
*
* @param value The state to set the relay.
*/
void Relay::Set(Relay::Value value) {
if (StatusIsFatal()) return;
int32_t status = 0;
switch (value) {
case kOff:
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
setRelayForward(m_relay_ports[m_channel], false, &status);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
setRelayReverse(m_relay_ports[m_channel], false, &status);
}
break;
case kOn:
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
setRelayForward(m_relay_ports[m_channel], true, &status);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
setRelayReverse(m_relay_ports[m_channel], true, &status);
}
break;
case kForward:
if (m_direction == kReverseOnly) {
wpi_setWPIError(IncompatibleMode);
break;
}
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
setRelayForward(m_relay_ports[m_channel], true, &status);
}
if (m_direction == kBothDirections) {
setRelayReverse(m_relay_ports[m_channel], false, &status);
}
break;
case kReverse:
if (m_direction == kForwardOnly) {
wpi_setWPIError(IncompatibleMode);
break;
}
if (m_direction == kBothDirections) {
setRelayForward(m_relay_ports[m_channel], false, &status);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
setRelayReverse(m_relay_ports[m_channel], true, &status);
}
break;
}
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
示例6: wpi_setWPIError
/**
* Validate that the data being packed will fit in the buffer.
*/
bool Dashboard::ValidateAdd(INT32 size)
{
if ((m_packPtr - m_localBuffer) + size > kMaxDashboardDataSize)
{
wpi_setWPIError(DashboardDataOverflow);
return false;
}
// Make sure printf is not being used at the same time.
if (m_localPrintBuffer[0] != 0)
{
wpi_setWPIError(DashboardDataCollision);
return false;
}
return true;
}
示例7: wpi_setWPIError
/**
* Returns a boolean indicating if the controller is an xbox controller.
*
* @param stick The joystick port number
* @return A boolean that is true if the controller is an xbox controller.
*/
bool DriverStation::GetJoystickIsXbox(uint32_t stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return false;
}
return (bool)m_joystickDescriptor[stick].isXbox;
}
示例8: GetNumChannelsToActivate
/**
* Set the sample rate on the module.
*
* This is a global setting for the module and effects all channels.
*
* @param samplesPerSecond The number of samples per channel per second.
*/
void AnalogModule::SetSampleRate(float samplesPerSecond)
{
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need float comparison with epsilon.
//wpi_assert(!sampleRateSet || GetSampleRate() == samplesPerSecond);
m_sampleRateSet = true;
// Compute the convert rate
UINT32 ticksPerSample = (UINT32)((float)kTimebase / samplesPerSecond);
UINT32 ticksPerConversion = ticksPerSample / GetNumChannelsToActivate();
// ticksPerConversion must be at least 80
if (ticksPerConversion < 80)
{
wpi_setWPIError(SampleRateTooHigh);
ticksPerConversion = 80;
}
// Atomically set the scan size and the convert rate so that the sample rate is constant
tAI::tConfig config;
config.ScanSize = GetNumChannelsToActivate();
config.ConvertRate = ticksPerConversion;
tRioStatusCode localStatus = NiFpga_Status_Success;
m_module->writeConfig(config, &localStatus);
wpi_setError(localStatus);
// Indicate that the scan size has been commited to hardware.
SetNumChannelsToActivate(0);
}
示例9: taskNameToId
/**
* Start the task that is responsible for sending images to the PC.
*/
int PCVideoServer::StartServerTask()
{
if (StatusIsFatal())
{
return -1;
}
int id = 0;
m_stopServer = false;
// Check for prior copy of running task
int oldId = taskNameToId((char*)m_serverTask.GetName());
if(oldId != ERROR)
{
// TODO: Report error. You are in a bad state.
taskDelete(oldId);
}
// spawn video server task
// this is done to ensure that the task is spawned with the
// floating point context save parameter.
bool started = m_serverTask.Start((int)this);
id = m_serverTask.GetID();
if (!started)
{
wpi_setWPIError(TaskError);
return id;
}
taskDelay(1);
return id;
}
示例10: sync
/**
* Free an allocated resource.
* After a resource is no longer needed, for example a destructor is called for a channel assignment
* class, Free will release the resource value so it can be reused somewhere else in the program.
*/
void Resource::Free(uint32_t index)
{
Synchronized sync(m_allocateLock);
if (index == ~0ul) return;
if (index >= m_size)
{
wpi_setWPIError(NotAllocated);
return;
}
if (!m_isAllocated[index])
{
wpi_setWPIError(NotAllocated);
return;
}
m_isAllocated[index] = false;
}
示例11: wpi_setWPIError
/**
* Convert a voltage to a raw value for a specified channel.
*
* This process depends on the calibration of each channel, so the channel
* must be specified.
*
* @todo This assumes raw values. Oversampling not supported as is.
*
* @param channel The channel to convert for.
* @param voltage The voltage to convert.
* @return The raw value for the channel.
*/
INT32 AnalogModule::VoltsToValue(INT32 channel, float voltage)
{
if (voltage > 10.0)
{
voltage = 10.0;
wpi_setWPIError(VoltageOutOfRange);
}
if (voltage < -10.0)
{
voltage = -10.0;
wpi_setWPIError(VoltageOutOfRange);
}
UINT32 LSBWeight = GetLSBWeight(channel);
INT32 offset = GetOffset(channel);
INT32 value = (INT32) ((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
return value;
}
示例12: wpi_setWPIError
/**
* Provide tank steering using the stored robot configuration.
* Drive the robot using two joystick inputs. The Y-axis will be selected from
* each Joystick object.
* @param leftStick The joystick to control the left side of the robot.
* @param rightStick The joystick to control the right side of the robot.
*/
void RobotDrive::TankDrive(GenericHID *leftStick, GenericHID *rightStick,
bool squaredInputs) {
if (leftStick == nullptr || rightStick == nullptr) {
wpi_setWPIError(NullParameter);
return;
}
TankDrive(leftStick->GetY(), rightStick->GetY(), squaredInputs);
}
示例13: m_analogInput
/**
* Create a new instance of Accelerometer from an existing AnalogInput.
*
* Make a new instance of accelerometer given an AnalogInput. This is
* particularly useful if the port is going to be read as an analog channel as
* well as through the Accelerometer class.
*
* @param channel The existing AnalogInput object for the analog input the
* accelerometer is connected to
*/
AnalogAccelerometer::AnalogAccelerometer(AnalogInput* channel)
: m_analogInput(channel, NullDeleter<AnalogInput>()) {
if (channel == nullptr) {
wpi_setWPIError(NullParameter);
} else {
InitAccelerometer();
}
}
示例14: wpi_setWPIError
/**
* Convert a voltage to a raw value for a specified channel.
*
* This process depends on the calibration of each channel, so the channel
* must be specified.
*
* @todo This assumes raw values. Oversampling not supported as is.
*
* @param channel The channel to convert for.
* @param voltage The voltage to convert.
* @return The raw value for the channel.
*/
int32_t AnalogModule::VoltsToValue(int32_t channel, float voltage)
{
if (voltage > 10.0)
{
voltage = 10.0;
wpi_setWPIError(VoltageOutOfRange);
}
if (voltage < -10.0)
{
voltage = -10.0;
wpi_setWPIError(VoltageOutOfRange);
}
uint32_t LSBWeight = GetLSBWeight(channel);
int32_t offset = GetOffset(channel);
int32_t value = (int32_t) ((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
return value;
}
示例15: switch
/**
* Set the relay state.
*
* Valid values depend on which directions of the relay are controlled by the
* object.
*
* When set to kBothDirections, the relay can be any of the four states:
* 0v-0v, 0v-12v, 12v-0v, 12v-12v
*
* When set to kForwardOnly or kReverseOnly, you can specify the constant for
* the direction or you can simply specify kOff and kOn. Using only kOff and
* kOn is recommended.
*
* @param value The state to set the relay.
*/
void Relay::Set(Relay::Value value) {
switch (value) {
case kOff:
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
go_pos = false;
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
go_neg = false;
}
break;
case kOn:
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
go_pos = true;
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
go_neg = true;
}
break;
case kForward:
if (m_direction == kReverseOnly) {
wpi_setWPIError(IncompatibleMode);
break;
}
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
go_pos = true;
}
if (m_direction == kBothDirections) {
go_neg = false;
}
break;
case kReverse:
if (m_direction == kForwardOnly) {
wpi_setWPIError(IncompatibleMode);
break;
}
if (m_direction == kBothDirections) {
go_pos = false;
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
go_neg = true;
}
break;
}
impl->Set((go_pos ? 1 : 0) + (go_neg ? -1 : 0));
}