Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into topic/#171
Browse files Browse the repository at this point in the history
  • Loading branch information
JSpencerPittman committed Mar 4, 2024
2 parents 583b927 + 4e07eb6 commit 985ddf8
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 178 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"image": "ghcr.io/missourimrdt/autonomy-jammy:latest",
// "image": "ghcr.io/missourimrdt/autonomy-jetpack:latest",
// "build": {
// "dockerfile": "Dockerfile_Jammy"
// "dockerfile": "Dockerfile_JetPack"
// "dockerfile": "Dockerfile_Jammy"
// "dockerfile": "Dockerfile_JetPack"
// },
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand Down Expand Up @@ -82,6 +82,8 @@
"C_Cpp.default.compilerPath": "/usr/bin/g++-10",
"C_Cpp.default.cppStandard": "c++20",
"C_Cpp.default.includePath": [
"/workspaces/Autonomy_Software/build/_deps/rovecomm_cpp-src/src/",
"/workspaces/Autonomy_Software/build/_deps/rovecomm_cpp-src/src/**",
"/usr/local/include/opencv4",
"/usr/local/include/opencv4/**",
"/usr/local/zed/include",
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(CPACK_GENERATOR "STGZ")
## Find RoveComm
FetchContent_Declare(RoveComm_CPP # Custom Network Protocol (RoveComm C++)
GIT_REPOSITORY https://github.com/MissouriMRDT/RoveComm_CPP.git # Source Code URL
GIT_TAG 111111d0a59eafcce9f6e3bfb3e6b3f24a60032c # Version 24.0.0
GIT_TAG 9440581e8b8cc69fab545e3ec6954bc005e6fb32 # Version 24.2.0
GIT_SHALLOW FALSE # Download only without history
GIT_PROGRESS TRUE # Forces progress status.
)
Expand Down
6 changes: 6 additions & 0 deletions data/Custom_Dictionaries/Autonomy-Dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ deque
Desaturate
devcontainer
diffdrive
DISPLAYSTATE
dockerfiles
dorny
doxdocgen
Doxygen
driveboard
DRIVELEFTRIGHT
endcond
Extention
feedforward
Expand All @@ -61,6 +63,7 @@ jetpack
jspencerpittman
jthread
keyscan
LEDRGB
LEFTCAM
MAINCAM
MAINCAN
Expand Down Expand Up @@ -102,7 +105,9 @@ setpoint
setpoints
SIMCAM
softprops
STARTAUTONOMY
statechart
STATEDISPLAY
statemachine
STATEMACHINEHANDLER
Struct
Expand All @@ -111,6 +116,7 @@ Styleguides
TAGDETECT
TAGDETECTOR
Tele
TELEOP
tensorflowtag
threadpool
tparam
Expand Down
10 changes: 10 additions & 0 deletions src/AutonomyConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ namespace constants
const std::string LOGGING_OUTPUT_PATH_ABSOLUTE = "./logs/"; // The absolute to write output logging and video files to.
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//// RoveComm Constants.
///////////////////////////////////////////////////////////////////////////

// Socket Ports.
const int ROVECOMM_UDP_PORT = 11000; // The UDP socket port to use for the main UDP RoveComm instance.
const int ROVECOMM_TCP_PORT = 12000; // The UDP socket port to use for the main UDP RoveComm instance.
const std::string ROVECOMM_TCP_INTERFACE_IP = ""; // The IP address to bind the socket to. If set to "", the socket will be bound to all available interfaces.
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//// Drive Constants.
///////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions src/AutonomyGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ namespace globals
DriveBoard* g_pDriveBoard;
MultimediaBoard* g_pMultimediaBoard;
NavigationBoard* g_pNavigationBoard;

// RoveComm Instances:
rovecomm::RoveCommUDP* g_pRoveCommUDPNode;
rovecomm::RoveCommTCP* g_pRoveCommTCPNode;
} // namespace globals
5 changes: 5 additions & 0 deletions src/AutonomyGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "handlers/WaypointHandler.h"

/// \cond
#include <RoveComm/RoveComm.h>
#include <chrono>
#include <ctime>
#include <iostream>
Expand Down Expand Up @@ -59,6 +60,10 @@ namespace globals
extern DriveBoard* g_pDriveBoard; // Global Drive Board Driver
extern MultimediaBoard* g_pMultimediaBoard; // Global Multimedia Board Driver
extern NavigationBoard* g_pNavigationBoard; // Global Navigation Board Driver

// RoveComm Instances:
extern rovecomm::RoveCommUDP* g_pRoveCommUDPNode; // Global RoveComm UDP Instance.
extern rovecomm::RoveCommTCP* g_pRoveCommTCPNode; // Global RoveComm TCP Instance.
} // namespace globals

#endif // AUTONOMY_GLOBALS_H
48 changes: 33 additions & 15 deletions src/drivers/DriveBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
#include "./DriveBoard.h"

#include "../AutonomyConstants.h"
#include "../AutonomyGlobals.h"
#include "../AutonomyLogging.h"

/// \cond
#include <RoveComm/RoveCommManifest.h>

/// \endcond

/******************************************************************************
* @brief Construct a new Drive Board::DriveBoard object.
*
Expand Down Expand Up @@ -83,32 +89,37 @@ diffdrive::DrivePowers DriveBoard::CalculateMove(const double dGoalSpeed,
/******************************************************************************
* @brief Sets the left and right drive powers of the drive board.
*
* @param dLeftSpeed - Left drive speed (-1 to 1)
* @param dRightSpeed - Right drive speed (-1 to 1)
* @param stDrivePowers - A struct containing info about the desired drive powers.
*
* @author clayjay3 ([email protected])
* @date 2023-09-21
******************************************************************************/
void DriveBoard::SendDrive(double dLeftSpeed, double dRightSpeed)
void DriveBoard::SendDrive(diffdrive::DrivePowers& stDrivePowers)
{
// Limit input values.
dLeftSpeed = std::clamp(dLeftSpeed, -1.0, 1.0);
dRightSpeed = std::clamp(dRightSpeed, -1.0, 1.0);
double dLeftSpeed = std::clamp(stDrivePowers.dLeftDrivePower, -1.0, 1.0);
double dRightSpeed = std::clamp(stDrivePowers.dRightDrivePower, -1.0, 1.0);

// Update member variables with new target speeds.
m_stDrivePowers.dLeftDrivePower = dLeftSpeed;
m_stDrivePowers.dRightDrivePower = dRightSpeed;

// TODO: Uncomment once RoveComm is implemented. This is commented to gid rid of unused variable warnings.
// // Remap -1.0 - 1.0 range to drive power range defined in constants. This is so that the driveboard/rovecomm can understand our input.
// float fDriveBoardLeftPower = numops::MapRange(float(dLeftSpeed), -1.0f, 1.0f, constants::DRIVE_MIN_POWER, constants::DRIVE_MAX_POWER);
// float fDriveBoardRightPower = numops::MapRange(float(dRightSpeed), -1.0f, 1.0f, constants::DRIVE_MIN_POWER, constants::DRIVE_MAX_POWER);
// // Limit the power to max and min effort defined in constants.
// fDriveBoardLeftPower = std::clamp(float(dLeftSpeed), constants::DRIVE_MIN_EFFORT, constants::DRIVE_MAX_EFFORT);
// fDriveBoardRightPower = std::clamp(float(dRightSpeed), constants::DRIVE_MIN_EFFORT, constants::DRIVE_MAX_EFFORT);

// Remap -1.0 - 1.0 range to drive power range defined in constants. This is so that the driveboard/rovecomm can understand our input.
float fDriveBoardLeftPower = numops::MapRange(float(dLeftSpeed), -1.0f, 1.0f, constants::DRIVE_MIN_POWER, constants::DRIVE_MAX_POWER);
float fDriveBoardRightPower = numops::MapRange(float(dRightSpeed), -1.0f, 1.0f, constants::DRIVE_MIN_POWER, constants::DRIVE_MAX_POWER);
// Limit the power to max and min effort defined in constants.
fDriveBoardLeftPower = std::clamp(float(dLeftSpeed), constants::DRIVE_MIN_EFFORT, constants::DRIVE_MAX_EFFORT);
fDriveBoardRightPower = std::clamp(float(dRightSpeed), constants::DRIVE_MIN_EFFORT, constants::DRIVE_MAX_EFFORT);

// Construct a RoveComm packet with the drive data.
rovecomm::RoveCommPacket<float> stPacket;
stPacket.unDataId = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_ID;
stPacket.unDataCount = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_COUNT;
stPacket.eDataType = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_TYPE;
stPacket.vData.emplace_back(fDriveBoardLeftPower);
stPacket.vData.emplace_back(fDriveBoardRightPower);
// Send drive command over RoveComm to drive board.
// TODO: Add RoveComm sendpacket.
globals::g_pRoveCommUDPNode->SendUDPPacket(stPacket, manifest::Core::IP_ADDRESS.IP_STR.c_str(), constants::ROVECOMM_UDP_PORT);

// Submit logger message.
LOG_DEBUG(logging::g_qSharedLogger, "Driving at: ({}, {})", m_stDrivePowers.dLeftDrivePower, m_stDrivePowers.dRightDrivePower);
Expand All @@ -127,8 +138,15 @@ void DriveBoard::SendStop()
m_stDrivePowers.dLeftDrivePower = 0.0;
m_stDrivePowers.dRightDrivePower = 0.0;

// Construct a RoveComm packet with the drive data.
rovecomm::RoveCommPacket<float> stPacket;
stPacket.unDataId = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_ID;
stPacket.unDataCount = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_COUNT;
stPacket.eDataType = manifest::Core::COMMANDS.find("DRIVELEFTRIGHT")->second.DATA_TYPE;
stPacket.vData.emplace_back(m_stDrivePowers.dLeftDrivePower);
stPacket.vData.emplace_back(m_stDrivePowers.dRightDrivePower);
// Send drive command over RoveComm to drive board.
// TODO: Add RoveComm sendpacket.
globals::g_pRoveCommUDPNode->SendUDPPacket(stPacket, manifest::Core::IP_ADDRESS.IP_STR.c_str(), constants::ROVECOMM_UDP_PORT);
}

/******************************************************************************
Expand Down
6 changes: 5 additions & 1 deletion src/drivers/DriveBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class DriveBoard
diffdrive::DrivePowers m_stDrivePowers; // Struct used to store the left and right drive powers of the robot.
controllers::PIDController* m_pPID; // The PID controller used for drive towards a heading.

/////////////////////////////////////////
// Declare private methods.
/////////////////////////////////////////

public:
/////////////////////////////////////////
// Declare public enums that are specific to and used within this class.
Expand All @@ -52,7 +56,7 @@ class DriveBoard
const double dGoalHeading,
const double dActualHeading,
const diffdrive::DifferentialControlMethod eKinematicsMethod);
void SendDrive(double dLeftSpeed, double dRightSpeed);
void SendDrive(diffdrive::DrivePowers& stDrivePowers);
void SendStop();

/////////////////////////////////////////
Expand Down
Loading

0 comments on commit 985ddf8

Please sign in to comment.