Compare commits

...

3 Commits

Author SHA1 Message Date
Tyler Veness
cc31079a11 [hal] Use setcap instead of setuid for setting thread priorities (#3613)
We originally moved to setuid admin so user programs could do other
things requiring admin if they wanted. However, these things, like
setting RT priorities of other processes, can usually be done instead as
admin during the GradleRIO 2022 deploy process, or adding commands to
the robotCommand script. By going back to setcap, we can simplify the
HAL code.
2021-10-04 09:49:34 -07:00
Tyler Veness
4676648b78 [wpimath] Upgrade to Drake v0.34.0 (#3607) 2021-09-29 15:39:47 -07:00
Thad House
c7594c9111 [build] Allow building wpilibc in cmake without cscore and opencv (#3605)
The hard dependency on cscore was removed a while ago in gradle, so make it not a hard requirement in cmake.
2021-09-27 21:37:04 -07:00
8 changed files with 88 additions and 72 deletions

View File

@@ -270,19 +270,20 @@ if (WITH_CSCORE)
set(CAMERASERVER_DEP_REPLACE ${CAMERASERVER_DEP_REPLACE_IMPL})
add_subdirectory(cscore)
add_subdirectory(cameraserver)
if (WITH_WPILIB)
set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
add_subdirectory(wpilibj)
add_subdirectory(wpilibc)
add_subdirectory(wpilibNewCommands)
if (WITH_OLD_COMMANDS)
add_subdirectory(wpilibOldCommands)
endif()
if (WITH_EXAMPLES)
add_subdirectory(wpilibcExamples)
endif()
add_subdirectory(myRobot)
endif()
if (WITH_WPILIB)
set(WPILIBC_DEP_REPLACE ${WPILIBC_DEP_REPLACE_IMPL})
add_subdirectory(wpilibj)
add_subdirectory(wpilibc)
add_subdirectory(wpilibNewCommands)
if (WITH_OLD_COMMANDS)
add_subdirectory(wpilibOldCommands)
endif()
if (WITH_EXAMPLES)
add_subdirectory(wpilibcExamples)
endif()
add_subdirectory(myRobot)
endif()
if (WITH_SIMULATION_MODULES AND NOT WITH_EXTERNAL_HAL)

View File

@@ -6,42 +6,9 @@
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
#include <cerrno>
#include <cstdlib>
#include <system_error>
#include <fmt/format.h>
#include "hal/Errors.h"
namespace {
class UidSetter {
public:
explicit UidSetter(uid_t uid) {
m_uid = geteuid();
if (uid == 0 && setuid(uid) == -1) {
throw std::system_error(errno, std::generic_category(),
fmt::format("setuid({}) failed", uid));
} else if (uid != 0 && seteuid(uid) == -1) {
throw std::system_error(errno, std::generic_category(),
fmt::format("seteuid({}) failed", uid));
}
}
~UidSetter() noexcept(false) {
if (geteuid() != m_uid && seteuid(m_uid) == -1) {
throw std::system_error(errno, std::generic_category(),
fmt::format("seteuid({}) failed", m_uid));
}
}
private:
uid_t m_uid;
};
} // namespace
namespace hal::init {
void InitializeThreads() {}
} // namespace hal::init
@@ -104,20 +71,13 @@ HAL_Bool HAL_SetThreadPriority(NativeThreadHandle handle, HAL_Bool realTime,
sch.sched_priority = 0;
}
try {
UidSetter uidSetter{0};
if (pthread_setschedparam(*reinterpret_cast<const pthread_t*>(handle),
scheduler, &sch)) {
*status = HAL_THREAD_PRIORITY_ERROR;
return false;
} else {
*status = 0;
return true;
}
} catch (const std::system_error& e) {
*status = HAL_SETUID_ERROR;
if (pthread_setschedparam(*reinterpret_cast<const pthread_t*>(handle),
scheduler, &sch)) {
*status = HAL_THREAD_PRIORITY_ERROR;
return false;
} else {
*status = 0;
return true;
}
}

View File

@@ -135,9 +135,6 @@
#define HAL_USE_LAST_ERROR_MESSAGE \
"HAL: Use HAL_GetLastError(status) to get last error"
#define HAL_SETUID_ERROR -1157
#define HAL_SETUID_ERROR_MESSAGE "HAL: Setting the effective user ID has failed"
#define HAL_CAN_BUFFER_OVERRUN -35007
#define HAL_CAN_BUFFER_OVERRUN_MESSAGE \
"HAL: CAN Output Buffer Full. Ensure a device is attached"

View File

@@ -0,0 +1,28 @@
diff --git b/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h a/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h
index cb0a4ee13..5d7a316f3 100644
--- b/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h
+++ a/wpimath/src/main/native/include/drake/math/discrete_algebraic_riccati_equation.h
@@ -4,6 +4,7 @@
#include <cstdlib>
#include <Eigen/Core>
+#include <wpi/SymbolExports.h>
namespace drake {
namespace math {
@@ -20,6 +21,7 @@ namespace math {
/// "On the Numerical Solution of the Discrete-Time Algebraic Riccati Equation"
/// by Thrasyvoulos Pappas, Alan J. Laub, and Nils R. Sandell
///
+WPILIB_DLLEXPORT
Eigen::MatrixXd DiscreteAlgebraicRiccatiEquation(
const Eigen::Ref<const Eigen::MatrixXd>& A,
const Eigen::Ref<const Eigen::MatrixXd>& B,
@@ -69,6 +71,7 @@ Eigen::MatrixXd DiscreteAlgebraicRiccatiEquation(
/// @throws std::runtime_error if Q NR⁻¹Nᵀ is not positive semi-definite.
/// @throws std::runtime_error if R is not positive definite.
///
+WPILIB_DLLEXPORT
Eigen::MatrixXd DiscreteAlgebraicRiccatiEquation(
const Eigen::Ref<const Eigen::MatrixXd>& A,
const Eigen::Ref<const Eigen::MatrixXd>& B,

View File

@@ -8,7 +8,7 @@ from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, wa
def main():
root, repo = setup_upstream_repo("https://github.com/RobotLocomotion/drake",
"v0.33.0")
"v0.34.0")
wpimath = os.path.join(root, "wpimath")
# Delete old install
@@ -61,7 +61,10 @@ def main():
os.path.join(wpimath, "src/test/native/include")
])
apply_patches(root, ["upstream_utils/drake-replace-dense-with-core.patch"])
apply_patches(root, [
"upstream_utils/drake-dllexport-dare.patch",
"upstream_utils/drake-replace-dense-with-core.patch"
])
if __name__ == "__main__":

View File

@@ -3,8 +3,6 @@ project(wpilibc)
include(CompileWarnings)
include(AddTest)
find_package( OpenCV REQUIRED )
configure_file(src/generate/WPILibVersion.cpp.in WPILibVersion.cpp)
file(GLOB_RECURSE
@@ -17,7 +15,18 @@ target_include_directories(wpilibc PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
$<INSTALL_INTERFACE:${include_dest}/wpilibc>)
wpilib_target_warnings(wpilibc)
target_link_libraries(wpilibc PUBLIC cameraserver hal ntcore cscore wpimath wpiutil ${OpenCV_LIBS})
if (WITH_CSCORE)
find_package( OpenCV )
target_link_libraries(wpilibc PUBLIC cameraserver cscore ${OpenCV_LIBS})
else()
target_compile_definitions(wpilibc PRIVATE DYNAMIC_CAMERA_SERVER)
# Add just the camera server include directory
target_include_directories(wpilibc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../cameraserver/src/main/native/include)
endif()
target_link_libraries(wpilibc PUBLIC hal ntcore wpimath wpiutil)
set_property(TARGET wpilibc PROPERTY FOLDER "libraries")
@@ -43,4 +52,9 @@ if (WITH_TESTS)
else()
target_compile_options(wpilibc_test PRIVATE /WX-)
endif()
if (NOT WITH_CSCORE)
target_compile_definitions(wpilibc_test PRIVATE DYNAMIC_CAMERA_SERVER)
# Add just the camera server include directory
target_include_directories(wpilibc_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../cameraserver/src/main/native/include)
endif()
endif()

View File

@@ -1,9 +1,8 @@
project (wpilibj)
find_package( OpenCV REQUIRED )
# Java bindings
if (WITH_JAVA)
find_package( OpenCV REQUIRED )
find_package(Java REQUIRED)
include(UseJava)
set(CMAKE_JAVA_COMPILE_FLAGS "-encoding" "UTF8" "-Xlint:unchecked")

View File

@@ -88,6 +88,14 @@ namespace internal {
// Report an assertion failure; will either Abort(...) or throw.
[[noreturn]] void AssertionFailed(const char* condition, const char* func,
const char* file, int line);
template <bool>
constexpr void DrakeAssertWasUsedWithRawPointer() {}
template<>
[[deprecated("\nDRAKE DEPRECATED: When using DRAKE_ASSERT or DRAKE_DEMAND on"
" a raw pointer, always write out DRAKE_ASSERT(foo != nullptr), do not write"
" DRAKE_ASSERT(foo) and rely on implicit pointer-to-bool conversion."
"\nThe deprecated code will be removed from Drake on or after 2021-12-01.")]]
constexpr void DrakeAssertWasUsedWithRawPointer<true>() {}
} // namespace internal
namespace assert {
// Allows for specialization of how to bool-convert Conditions used in
@@ -114,6 +122,8 @@ struct ConditionTraits {
typedef ::drake::assert::ConditionTraits< \
typename std::remove_cv_t<decltype(condition)>> Trait; \
static_assert(Trait::is_valid, "Condition should be bool-convertible."); \
::drake::internal::DrakeAssertWasUsedWithRawPointer< \
std::is_pointer_v<decltype(condition)>>(); \
if (!Trait::Evaluate(condition)) { \
::drake::internal::AssertionFailed( \
#condition, __func__, __FILE__, __LINE__); \
@@ -139,10 +149,14 @@ namespace drake {
constexpr bool kDrakeAssertIsArmed = false;
constexpr bool kDrakeAssertIsDisarmed = true;
} // namespace drake
# define DRAKE_ASSERT(condition) static_assert( \
::drake::assert::ConditionTraits< \
typename std::remove_cv_t<decltype(condition)>>::is_valid, \
"Condition should be bool-convertible.");
# define DRAKE_ASSERT(condition) do { \
static_assert( \
::drake::assert::ConditionTraits< \
typename std::remove_cv_t<decltype(condition)>>::is_valid, \
"Condition should be bool-convertible."); \
::drake::internal::DrakeAssertWasUsedWithRawPointer< \
std::is_pointer_v<decltype(condition)>>(); \
} while (0)
# define DRAKE_ASSERT_VOID(expression) static_assert( \
std::is_convertible_v<decltype(expression), void>, \
"Expression should be void.")