Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Simulation Interface Draft Stubs #49

Merged
merged 24 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a176a07
Updated can_transceiver.h and .cpp according to subscribe to /Simulat…
colinli02 Mar 3, 2023
d7ffd62
can_transceiver_ros_intf.cpp: Moved /Simulator sub
colinli02 Mar 25, 2023
eb304e5
Removed duplicate code (was placed in wrong cmake)
colinli02 Mar 25, 2023
873f389
Merge remote-tracking branch 'origin/main' into user/colinli02/16-CAN…
colinli02 Jul 27, 2023
d1f710e
Cleaned up comments within functions
colinli02 Jul 27, 2023
a4d6eb7
Updated based on custom_interfaces topics
colinli02 Jul 27, 2023
9e31613
Added ability to publish to multiple ROS topics
colinli02 Sep 16, 2023
b73db93
Add custom_interfaces dependency to CMake
hhenry01 Sep 27, 2023
a6c532c
Added subscription for mock_gps, mock_wind_sensors
colinli02 Oct 4, 2023
f603726
Added back removed RCLCPP::spin, commented out
colinli02 Oct 7, 2023
63e5444
Fixed rclcpp::spin error
colinli02 Oct 7, 2023
17c122f
Added functionality to spin pub & sub
colinli02 Oct 7, 2023
fcbbfe4
Added print for all pubsub
colinli02 Oct 7, 2023
9b4b08e
Fixed print statements related to subbing mocks
colinli02 Oct 7, 2023
1f0089f
Fixed generic sensors data issue
colinli02 Oct 28, 2023
051d80b
- Removed RCLCPP_INFO
colinli02 Nov 1, 2023
e6dee05
- Removed autogenerated file from running ros2
colinli02 Nov 1, 2023
a15109d
- Resolved branch conflicts
colinli02 Nov 1, 2023
cd5fc16
- Fixed formatting and removed unnecessary headers
colinli02 Nov 8, 2023
0dd4d7d
Merge branch 'main' into user/colinli02/16-CAN-Sim-Interface-Stubs
colinli02 Nov 8, 2023
03e4e65
- Replaced with constants defined under ros_info.h
colinli02 Nov 8, 2023
45edfb6
- Updated formatting to match ROS guidelines
colinli02 Nov 11, 2023
7c43629
- Removed un-used headers
colinli02 Nov 11, 2023
e190e61
Split into two nodes CanTrxRosIntf, CanSimIntf
colinli02 Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions projects/can_transceiver/inc/can_frame_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static std::array<std::string, CanId::CAN_ID_MAX> CAN_DEVICE_NAMES = {"Placehold

/**
* Custom exception for when an attempt is made to construct a CAN object with a mismatched ID
*
*
*/
class CanIdMismatchException : public std::runtime_error
{
Expand All @@ -33,7 +33,7 @@ class CanIdMismatchException : public std::runtime_error

/**
* Placeholder CAN device
*
*
*/
struct Placeholder0
{
Expand All @@ -58,21 +58,21 @@ struct Placeholder0

/**
* @brief Construct the object from a CAN frame
*
*
* @param frame CAN frame
*/
explicit Placeholder0(const CanFrame & frame);

/**
* @brief Construct the object from a ROS msg
*
*
*/
Placeholder0(/* Placeholder0 ROS msg */);
};

/**
* Placeholder CAN device
*
*
*/
struct Placeholder1
{
Expand All @@ -93,14 +93,14 @@ struct Placeholder1

/**
* @brief Construct the object from a CAN frame
*
*
* @param frame CAN frame
*/
explicit Placeholder1(const CanFrame & frame);

/**
* @brief Construct the object from a ROS msg
*
*
*/
Placeholder1(/* Placeholder1 ROS msg */);

Expand All @@ -115,7 +115,7 @@ struct Placeholder1

/**
* Rudder Command Frame
*
*
*/
struct RudderCmd
{
Expand All @@ -140,7 +140,7 @@ struct RudderCmd

/**
* @brief Convert this object into a standard Linux CAN frame and return it
*
*
* @return Rudder command as a standard Linux CAN frame object
*/
CanFrame toLinuxCan();
Expand Down
30 changes: 15 additions & 15 deletions projects/can_transceiver/inc/can_transceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
/**
* Abstract CAN Transceiver Class
* Handles transmission and reception of data to and from the hardware/simulator
*
*
*/
class CanTransceiver
{
public:
/**
* @brief Destroy the Can Transceiver object
*
*
*/
virtual ~CanTransceiver() = 0;

/**
* @brief Call when a new command (ex. rudder command) needs to be executed
* Passes the command down to the hardware/simulator
*
*
*/
void onNewCmd(CanId id /*, other data fields... */);

/**
* @brief Retrieve the most recent set of sensors data
*
*
* @return Data in some format - string is just a placeholder; DO NOT USE STRING IN ACTUAL IMPLEMENTATION
*/
std::string getRecentSensors();
Expand All @@ -40,42 +40,42 @@ class CanTransceiver
void * sensor_buf_;
/**
* @brief Retrieve latest incoming data from hardware/simulator and process it
*
*
*/
virtual void receive() = 0;

/**
* @brief Send a command to the hardware/simulator
*
*
* @param frame Command frame to send
*/
virtual void send(const CanFrame & frame) const = 0;

/**
* @brief Call on receiving a new CAN data frame from hardware/simulator
*
*
* @param frame received CAN data frame
*/
void onNewCanData(const CanFrame & frame);
};

/**
* Implementation of CAN Transceiver that interfaces with CAN hardware
*
*
*/
class CanbusIntf : public CanTransceiver
{
public:
/**
* @brief Construct a new Canbus Intf object and start listening for incoming data on a new thread
*
* @param can_inst
*
* @param can_inst
*/
explicit CanbusIntf(const std::string & can_inst);

/**
* @brief Destroy the Canbus Intf object
*
*
*/
~CanbusIntf();

Expand All @@ -88,23 +88,23 @@ class CanbusIntf : public CanTransceiver

/**
* @brief Retrieve latest incoming CAN frame from hardware and process it
*
*
*/
void receive();

/**
* @brief Send a command to hardware
*
*
* @param frame command frame to send
*/
void send(const CanFrame & frame) const;
};

colinli02 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Implementation of CAN Transceiver that interfaces with the simulator
*
*
*/
class CanSimIntf : public CanTransceiver, public rclcpp::Node
class CanSimTransceiver : public CanTransceiver
{
void receive();
};
4 changes: 2 additions & 2 deletions projects/can_transceiver/src/can_frame_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace
{
/**
* @brief Verify that a given CAN frame to construct a device has a valid ID assigned to it
*
*
* @param actual_can_id ID of the given CAN frame
* @param expected_can_id ID of the device object that is attempting to be constructed
*/
Expand All @@ -20,7 +20,7 @@ void checkId(const canid_t & actual_can_id, const CanId & expected_can_id)
/**
* @brief Default CAN device object constructor for when construction is a 1:1 mapping between raw data and data fields
* Copies data from source CAN frame to a given buffer
*
*
* @param frame Source CAN frame
* @param expected_can_id Device ID of CAN Frame that is attempting to be constructed
* @param buf Output buffer for data to be copied into
Expand Down
4 changes: 1 addition & 3 deletions projects/can_transceiver/src/can_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace

/**
* @brief Format a CAN frame into a string for debugging and logging
*
*
* @param frame CAN frame to format
* @return String representation of frame
*/
Expand Down Expand Up @@ -114,5 +114,3 @@ void CanbusIntf::send(const CanFrame & frame) const
std::cerr << fmtCanFrameDbgStr(frame) << std::endl;
}
}

void CanSimIntf::receive() {}
Loading