mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Add FPGA Duty Cycle support (#1987)
This commit is contained in:
committed by
Peter Johnson
parent
509819d83f
commit
1d695a1660
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -37,11 +37,17 @@ extern "C" {
|
||||
* Initializes an analog trigger.
|
||||
*
|
||||
* @param portHandle the analog input to use for triggering
|
||||
* @param index the trigger index value (output)
|
||||
* @return the created analog trigger handle
|
||||
*/
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
HAL_AnalogInputHandle portHandle, int32_t* index, int32_t* status);
|
||||
HAL_AnalogInputHandle portHandle, int32_t* status);
|
||||
|
||||
/**
|
||||
* Initializes an analog trigger with a Duty Cycle input
|
||||
*
|
||||
*/
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle(
|
||||
HAL_DutyCycleHandle dutyCycleHandle, int32_t* status);
|
||||
|
||||
/**
|
||||
* Frees an analog trigger.
|
||||
@@ -54,7 +60,8 @@ void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
/**
|
||||
* Sets the raw ADC upper and lower limits of the analog trigger.
|
||||
*
|
||||
* HAL_SetAnalogTriggerLimitsVoltage is likely better in most cases.
|
||||
* HAL_SetAnalogTriggerLimitsVoltage or HAL_SetAnalogTriggerLimitsDutyCycle
|
||||
* is likely better in most cases.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @param lower the lower ADC value
|
||||
@@ -77,12 +84,19 @@ void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_SetAnalogTriggerLimitsDutyCycle(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, double lower, double upper,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Configures the analog trigger to use the averaged vs. raw values.
|
||||
*
|
||||
* If the value is true, then the averaged value is selected for the analog
|
||||
* trigger, otherwise the immediate value is used.
|
||||
*
|
||||
* This is not allowed to be used if filtered mode is set.
|
||||
* This is not allowed to be used with Duty Cycle based inputs.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @param useAveragedValue true to use averaged values, false for raw
|
||||
*/
|
||||
@@ -96,6 +110,8 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
* is designed to help with 360 degree pot applications for the period where the
|
||||
* pot crosses through zero.
|
||||
*
|
||||
* This is not allowed to be used if averaged mode is set.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @param useFilteredValue true to use filtered values, false for average or
|
||||
* raw
|
||||
@@ -137,6 +153,15 @@ HAL_Bool HAL_GetAnalogTriggerTriggerState(
|
||||
HAL_Bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analogTriggerHandle,
|
||||
HAL_AnalogTriggerType type,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the AnlogTrigger.
|
||||
*
|
||||
* @param analogTriggerHandle the trigger handle
|
||||
* @return the FPGA index
|
||||
*/
|
||||
int32_t HAL_GetAnalogTriggerFPGAIndex(
|
||||
HAL_AnalogTriggerHandle analogTriggerHandle, int32_t* status);
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tCounter.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDIO.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDMA.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDutyCycle.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tEncoder.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tGlobal.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tInterrupt.h>
|
||||
|
||||
102
hal/src/main/native/include/hal/DutyCycle.h
Normal file
102
hal/src/main/native/include/hal/DutyCycle.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/AnalogTrigger.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialize a DutyCycle input.
|
||||
*
|
||||
* @param digitalSourceHandle the digital source to use (either a
|
||||
* HAL_DigitalHandle or a HAL_AnalogTriggerHandle)
|
||||
* @param triggerType the analog trigger type of the source if it is
|
||||
* an analog trigger
|
||||
* @return thre created duty cycle handle
|
||||
*/
|
||||
HAL_DutyCycleHandle HAL_InitializeDutyCycle(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType triggerType,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Free a DutyCycle.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
*/
|
||||
void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle);
|
||||
|
||||
/**
|
||||
* Indicates the duty cycle is used by a simulated device.
|
||||
*
|
||||
* @param handle the duty cycle handle
|
||||
* @param device simulated device handle
|
||||
*/
|
||||
void HAL_SetDutyCycleSimDevice(HAL_DutyCycleHandle handle,
|
||||
HAL_SimDeviceHandle device);
|
||||
|
||||
/**
|
||||
* Get the frequency of the duty cycle signal.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return frequency in Hertz
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the output ratio of the duty cycle signal.
|
||||
*
|
||||
* <p> 0 means always low, 1 means always high.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return output ratio between 0 and 1
|
||||
*/
|
||||
double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the raw output ratio of the duty cycle signal.
|
||||
*
|
||||
* <p> 0 means always low, an output equal to
|
||||
* GetOutputScaleFactor() means always high.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return output ratio in raw units
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleOutputRaw(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the scale factor of the output.
|
||||
*
|
||||
* <p> An output equal to this value is always high, and then linearly scales
|
||||
* down to 0. Divide the result of getOutputRaw by this in order to get the
|
||||
* percentage between 0 and 1.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return the output scale factor
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleOutputScaleFactor(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Get the FPGA index for the DutyCycle.
|
||||
*
|
||||
* @param dutyCycleHandle the duty cycle handle
|
||||
* @return the FPGA index
|
||||
*/
|
||||
int32_t HAL_GetDutyCycleFPGAIndex(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -117,6 +117,9 @@
|
||||
#define HAL_CAN_TIMEOUT -1154
|
||||
#define HAL_CAN_TIMEOUT_MESSAGE "HAL: CAN Receive has Timed Out"
|
||||
|
||||
#define HAL_SIM_NOT_SUPPORTED -1155
|
||||
#define HAL_SIM_NOT_SUPPORTED_MESSAGE "HAL: Method not supported in sim"
|
||||
|
||||
#define VI_ERROR_SYSTEM_ERROR_MESSAGE "HAL - VISA: System Error";
|
||||
#define VI_ERROR_INV_OBJECT_MESSAGE "HAL - VISA: Invalid Object"
|
||||
#define VI_ERROR_RSRC_LOCKED_MESSAGE "HAL - VISA: Resource Locked"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -144,6 +144,13 @@ int32_t HAL_GetNumPDPModules(void);
|
||||
* @return the number of PDP channels
|
||||
*/
|
||||
int32_t HAL_GetNumPDPChannels(void);
|
||||
|
||||
/**
|
||||
* Gets the number of duty cycle inputs in the current system.
|
||||
*
|
||||
* @return the number of Duty Cycle inputs
|
||||
*/
|
||||
int32_t HAL_GetNumDutyCycles(void);
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -57,6 +57,8 @@ typedef HAL_Handle HAL_SimDeviceHandle;
|
||||
|
||||
typedef HAL_Handle HAL_SimValueHandle;
|
||||
|
||||
typedef HAL_Handle HAL_DutyCycleHandle;
|
||||
|
||||
typedef HAL_CANHandle HAL_PDPHandle;
|
||||
|
||||
typedef int32_t HAL_Bool;
|
||||
|
||||
@@ -66,6 +66,7 @@ enum class HAL_HandleEnum {
|
||||
SimulationJni = 18,
|
||||
CAN = 19,
|
||||
SerialPort = 20,
|
||||
DutyCycle = 21
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
enum HALSIM_AnalogTriggerMode : int32_t {
|
||||
HALSIM_AnalogTriggerUnassigned,
|
||||
HALSIM_AnalogTriggerFiltered,
|
||||
HALSIM_AnalogTriggerDutyCycle,
|
||||
HALSIM_AnalogTriggerAveraged
|
||||
};
|
||||
|
||||
|
||||
52
hal/src/main/native/include/mockdata/DutyCycleData.h
Normal file
52
hal/src/main/native/include/mockdata/DutyCycleData.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "NotifyListener.h"
|
||||
#include "hal/Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HALSIM_ResetDutyCycleData(int32_t index);
|
||||
int32_t HALSIM_GetDutyCycleDigitalChannel(int32_t index);
|
||||
|
||||
int32_t HALSIM_RegisterDutyCycleInitializedCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDutyCycleInitializedCallback(int32_t index, int32_t uid);
|
||||
HAL_Bool HALSIM_GetDutyCycleInitialized(int32_t index);
|
||||
void HALSIM_SetDutyCycleInitialized(int32_t index, HAL_Bool initialized);
|
||||
|
||||
HAL_SimDeviceHandle HALSIM_GetDutyCycleSimDevice(int32_t index);
|
||||
|
||||
int32_t HALSIM_RegisterDutyCycleOutputCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDutyCycleOutputCallback(int32_t index, int32_t uid);
|
||||
double HALSIM_GetDutyCycleOutput(int32_t index);
|
||||
void HALSIM_SetDutyCycleOutput(int32_t index, double output);
|
||||
|
||||
int32_t HALSIM_RegisterDutyCycleFrequencyCallback(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelDutyCycleFrequencyCallback(int32_t index, int32_t uid);
|
||||
int32_t HALSIM_GetDutyCycleFrequency(int32_t index);
|
||||
void HALSIM_SetDutyCycleFrequency(int32_t index, int32_t frequency);
|
||||
|
||||
void HALSIM_RegisterDutyCycleAllCallbacks(int32_t index,
|
||||
HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
71
hal/src/main/native/include/simulation/DutyCycleSim.h
Normal file
71
hal/src/main/native/include/simulation/DutyCycleSim.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "mockdata/DutyCycleData.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
class DutyCycleSim {
|
||||
public:
|
||||
explicit DutyCycleSim(int index) { m_index = index; }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetInitialized() const {
|
||||
return HALSIM_GetDutyCycleInitialized(m_index);
|
||||
}
|
||||
|
||||
void SetInitialized(bool initialized) {
|
||||
HALSIM_SetDutyCycleInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleFrequencyCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleFrequencyCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int GetFrequency() const { return HALSIM_GetDutyCycleFrequency(m_index); }
|
||||
|
||||
void SetFrequency(int count) { HALSIM_SetDutyCycleFrequency(m_index, count); }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelDutyCycleOutputCallback);
|
||||
store->SetUid(HALSIM_RegisterDutyCycleOutputCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double GetOutput() const { return HALSIM_GetDutyCycleOutput(m_index); }
|
||||
|
||||
void SetOutput(double period) { HALSIM_SetDutyCycleOutput(m_index, period); }
|
||||
|
||||
void ResetData() { HALSIM_ResetDutyCycleData(m_index); }
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
Reference in New Issue
Block a user