Skip to content

Commit

Permalink
Clean up the rest of swerve
Browse files Browse the repository at this point in the history
  • Loading branch information
imisaacwu committed Mar 1, 2025
1 parent e012252 commit 97ce9de
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 66 deletions.
121 changes: 59 additions & 62 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13) # Latest versions of Ubuntu should have at least 3.16;
# argparse library requires 3.12.4 currently
cmake_minimum_required(VERSION 3.13) #Latest versions of Ubuntu should have at least 3.16;
#argparse library requires 3.12.4 currently

set(CMAKE_CXX_STANDARD 17) # 11 For the json library, 17 for std library features
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -8,13 +8,14 @@ project(Rover LANGUAGES CXX C)

include(FetchContent)

# If a build type was not explicitly specified, default to "RelWithDebInfo" (Same optimization
# as the "Release" configuration but with debugging symbols).
#If a build type was not explicitly specified, default to "RelWithDebInfo"(Same optimization
#as the "Release" configuration but with debugging symbols).
#
# To change, you can pass -DCMAKE_BUILD_TYPE=... where ... is the configuration you would like
# to use. For example, if you want to do a full debug build (little to no optimization, with
# debugging symbols), add -DCMAKE_BUILD_TYPE=Debug to your `cmake` command. You may want to do
# a full debug build if code you want to debug gets optimized out by the compiler.
#To change, you can pass - DCMAKE_BUILD_TYPE = ... where... is the configuration you would like
#to use.For example, if you want to do a full debug build(little to no optimization, with
#debugging symbols), \
add - DCMAKE_BUILD_TYPE = Debug to your `cmake` command.You may want to do
#a full debug build if code you want to debug gets optimized out by the compiler.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "The type of build to perform.")
set(AVAILABLE_BUILD_TYPES "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${AVAILABLE_BUILD_TYPES})
Expand All @@ -23,17 +24,17 @@ Building ${CMAKE_BUILD_TYPE} configuration...\n\
Add -DCMAKE_BUILD_TYPE=... to change\n\
========================================")

# Generate a compile_commands.json file by default unless explicitly disabled.
# This allows editors like Visual Studio Code to be able to index the project correctly and
# locate header files and libraries.
#Generate a compile_commands.json file by default unless explicitly disabled.
#This allows editors like Visual Studio Code to be able to index the project correctly and
#locate header files and libraries.
if(NOT CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE STRING "Enable/Disable output of compile commands
during generation." FORCE)
endif()

##====== Module settings ======
# These variables control whether various modules are enabled or disabled. The goal is to allow
# a user to selectively exclude modules that they do not need.
#These variables control whether various modules are enabled or disabled.The goal is to allow
#a user to selectively exclude modules that they do not need.
set(GPS "ARDUPILOT" CACHE STRING "GPS interface to use.")
set(AVAILABLE_GPS "USB" "ARDUPILOT" "NONE")
set_property(CACHE GPS PROPERTY STRINGS ${AVAILABLE_GPS})
Expand All @@ -60,49 +61,48 @@ message(" World Interface:\t${WORLD_INTERFACE}")
message("========================================")

##====== Dependencies ======
# Some of these are optional depending on module settings above.
#Some of these are optional depending on module settings above.

# Get the Eigen linear algebra library. Eigen's CMake config includes its headers as user
# headers instead of system headers by default, so explicitly force them to be system includes
# here to avoid the compiler spamming warnings at us for stuff in the Eigen headers.
#Get the Eigen linear algebra library.Eigen's CMake config includes its headers as user
#headers instead of system headers by default, so explicitly force them to be system includes
#here to avoid the compiler spamming warnings at us for stuff in the Eigen headers.
find_package(Eigen3 REQUIRED NO_MODULE)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})

# Find the WebSocket++ library and Boost (provides the ASIO backend for Websocket++ and also
# provides the program_options argument parser). Only the `system` component of Boost is
# currently required.
#Find the WebSocket++ library and Boost(provides the ASIO backend for Websocket++ and also
#provides the program_options argument parser).Only the `system` component of Boost is
#currently required.
find_package(websocketpp REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)

# Find Frozen, library used for constexpr immutable containers
#Find Frozen, library used for constexpr immutable containers
find_package(frozen REQUIRED)
# Frozen is just an interface library, only containing headers and some CMake settings. It
# should be fine to "link" the library to every target, since if the headers are not included,
# it will not have any effect on size or performance. This will help us not have to worry about
# making sure the headers are available in every file that includes Constants.h, for example.
#Frozen is just an interface library, only containing headers and some CMake settings.It
#should be fine to "link" the library to every target, since if the headers are not included,
#it will not have any effect on size or performance.This will help us not have to worry about
#making sure the headers are available in every file that includes Constants.h, for example.
link_libraries(frozen::frozen)

# Find argparse, library used for parsing command line arguments
#Find argparse, library used for parsing command line arguments
find_package(argparse REQUIRED)


# Find the JSON library
#Find the JSON library
find_package(nlohmann_json 3.2.0 REQUIRED)

# Find the CAN library; contains packet and protocol definitions and does not
# actually require physical CAN to be present.
#Find the CAN library; contains packet and protocol definitions and does not
#actually require physical CAN to be present.
FetchContent_Declare(
HindsightCAN
GIT_REPOSITORY https://github.com/huskyroboticsteam/HindsightCAN.git
GIT_TAG 45b1544f20e7ba6dd0db19fb97e947430031fc6a
GIT_TAG 675aa2c32a5b6cdb24f3f2b8aae5b7e43d717bf6
)
FetchContent_MakeAvailable(HindsightCAN)

FetchContent_Declare(LoguruGitRepo
GIT_REPOSITORY "https://github.com/emilk/loguru"
GIT_TAG "master"
)
# set any loguru compile-time flags before calling MakeAvailable()
#set any loguru compile - time flags before calling MakeAvailable()
set(LOGURU_WITH_STREAMS TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_MakeAvailable(LoguruGitRepo) # defines target 'loguru::loguru'
Expand All @@ -115,13 +115,13 @@ if(WITH_TESTS)
find_package(Catch2 REQUIRED)
endif()

# Libraries needed to interface with real-life sensors. If we aren't using the real world
# interface, these aren't needed.
#Libraries needed to interface with real - life sensors.If we aren't using the real world
#interface, these aren't needed.
if(WORLD_INTERFACE STREQUAL "REAL")
if(GPS STREQUAL "USB")
# Find pkg-config (needed for libgps, as it doesn't have CMake configuration)
#Find pkg - config(needed for libgps, as it doesn't have CMake configuration)
find_package(PkgConfig REQUIRED)
# Find the libgps USB GPS library.
#Find the libgps USB GPS library.
pkg_check_modules(libgps REQUIRED libgps)
endif()
endif()
Expand All @@ -137,7 +137,7 @@ add_library(camera SHARED
)
target_link_libraries(camera PUBLIC ${OpenCV_LIBS})

# shared library for utility code
#shared library for utility code
add_library(utils SHARED
utils/core.cpp
utils/random.cpp
Expand All @@ -151,27 +151,26 @@ add_library(utils SHARED
base64/base64_img.cpp
kinematics/DiffDriveKinematics.cpp
kinematics/DiffWristKinematics.cpp
kinematics/SwerveDriveKinematics.cpp
world_interface/data.cpp)
target_link_libraries(utils ${OpenCV_LIBS})

## ====== CAN Interfaces =======
# Stub CAN interface is used for the tests (and for the Rover if
# CAN is disabled) and the real CAN interface is used for the Rover if CAN is
# enabled.
#Stub CAN interface is used for the tests(and for the Rover if
#CAN is disabled) and the real CAN interface is used for the Rover if CAN is
#enabled.

# Common CAN source files
#Common CAN source files

# **DON'T MAKE THIS SHARED**
# Making this library shared causes some memory fuckery
# No clue why but CAN I/O goes to shit. Don't do it.
#** DON'T MAKE THIS SHARED**
#Making this library shared causes some memory fuckery
#No clue why but CAN I / O goes to shit.Don't do it.
add_library(can_interface STATIC)
target_sources(can_interface PRIVATE
CAN/CANMotor.cpp
CAN/CANUtils.cpp
)

# Hardware specific source files
#Hardware specific source files
target_sources(can_interface PRIVATE
CAN/CAN.cpp)
target_link_libraries(can_interface PUBLIC
Expand All @@ -196,7 +195,7 @@ else()
endif()

## ====== World Interfaces =======
# hardware-agnostic utilities and common code for world interface
#hardware - agnostic utilities and common code for world interface
add_library(world_interface_core STATIC
world_interface/gps_common_interface.cpp
ar/Detector.cpp
Expand All @@ -209,7 +208,7 @@ add_library(world_interface_core STATIC
target_include_directories(world_interface_core SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(world_interface_core PUBLIC ${vision_libs} opencv_aruco ${OpenCV_LIBS} utils camera)

# CAN library (above) requires some utilities from this
#CAN library(above) requires some utilities from this
target_link_libraries(can_interface PUBLIC utils)

add_library(stub_world_interface STATIC
Expand Down Expand Up @@ -254,7 +253,6 @@ target_link_libraries(video

add_library(control SHARED
control/TrapezoidalVelocityProfile.cpp
control/SwerveController.cpp
)
target_link_libraries(control utils)

Expand All @@ -269,9 +267,9 @@ add_library(constants SHARED Constants.cpp)
link_libraries(constants)

add_executable(Rover Rover.cpp)
# **DON'T MAKE THIS SHARED**
# Making this library shared causes some memory fuckery
# No clue why but CAN I/O goes to shit. Don't do it.
#** DON'T MAKE THIS SHARED**
#Making this library shared causes some memory fuckery
#No clue why but CAN I / O goes to shit.Don't do it.
add_library(rover_common STATIC
Globals.cpp
control_interface.cpp
Expand Down Expand Up @@ -308,38 +306,37 @@ target_link_libraries(TunePID ${vision_libs})
if(WITH_TESTS)
add_executable(tests
Tests.cpp
# AR Detection tests
#AR Detection tests
ar/DetectorTests.cpp
ar/MarkerSetTests.cpp
# Camera tests
#Camera tests
../tests/camera/CameraParamsTests.cpp
# GPS tests
#GPS tests
../tests/gps/GPSDatumTest.cpp
../tests/gps/GPSConverterTest.cpp
# Controller tests
#Controller tests
../tests/control/TrapezoidalVelocityProfileTest.cpp
../tests/control/JacobianControllerTest.cpp
../tests/control/PIDControllerTest.cpp
../tests/control/PlanarArmControllerTest.cpp
# Kinematics tests
#Kinematics tests
../tests/kinematics/DiffDriveKinematicsTest.cpp
../tests/kinematics/SwerveDriveKinematicsTest.cpp
../tests/kinematics/PlanarArmFKTest.cpp
../tests/kinematics/FabrikSolver2DTest.cpp
# Filter tests
#Filter tests
../tests/filters/RollingAvgFilterTest.cpp
../tests/filters/EKFTest.cpp
../tests/filters/MultiSensorEKFTest.cpp
../tests/filters/StateSpaceUtilsTest.cpp
# Command tests
#Command tests
../tests/commands/DriveToWaypointCommandTest.cpp
# Util tests
#Util tests
../tests/util/CoreTest.cpp
../tests/util/DataTest.cpp
../tests/util/MathTest.cpp
../tests/util/TimeTest.cpp
../tests/util/SchedulerTest.cpp
# Protocol/teleop tests
#Protocol / teleop tests
../tests/kinematics/DiffWristKinematicsTest.cpp)

target_link_libraries(tests
Expand Down
1 change: 0 additions & 1 deletion src/network/MissionControlMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace net::mc {
// request keys
constexpr const char* EMERGENCY_STOP_REQ_TYPE = "emergencyStopRequest";
constexpr const char* OPERATION_MODE_REQ_TYPE = "operationModeRequest";
constexpr const char* DRIVE_MODE_REQ_TYPE = "swerveDriveModeRequest";
constexpr const char* DRIVE_REQ_TYPE = "driveRequest";
constexpr const char* DRIVE_TANK_REQ_TYPE = "tankDriveRequest";
constexpr const char* ARM_IK_ENABLED_TYPE = "requestArmIKEnabled";
Expand Down
1 change: 0 additions & 1 deletion src/network/MissionControlProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class MissionControlProtocol : public WebSocketProtocol { // TODO: add documenta

void handleEmergencyStopRequest(const json& j);
void handleOperationModeRequest(const json& j);
void handleDriveModeRequest(const json& j);
void handleTankDriveRequest(const json& j);
void handleCameraStreamOpenRequest(const json& j);
void handleCameraStreamCloseRequest(const json& j);
Expand Down
4 changes: 2 additions & 2 deletions src/world_interface/real_world_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ constexpr auto potMotors = frozen::make_unordered_map<motorid_t, potparams_t>({

/** @brief A mapping of motorids to their corresponding serial number. */
constexpr auto motorSerialIDMap = frozen::make_unordered_map<motorid_t, can::deviceserial_t>(
{{motorid_t::leftTread, DEVICE_SERIAL_MOTOR_CHASSIS_FL},
{motorid_t::rightTread, DEVICE_SERIAL_MOTOR_CHASSIS_FR},
{{motorid_t::leftTread, DEVICE_SERIAL_TREAD_LEFT},
{motorid_t::rightTread, DEVICE_SERIAL_TREAD_RIGHT},
{motorid_t::armBase, DEVICE_SERIAL_MOTOR_BASE},
{motorid_t::shoulder, DEVICE_SERIAL_MOTOR_SHOULDER},
{motorid_t::elbow, DEVICE_SERIAL_MOTOR_ELBOW},
Expand Down

0 comments on commit 97ce9de

Please sign in to comment.