Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/linting_auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.10.19'
python-version: '3.10.20'

- name: Install Python dependencies
run: pip install autopep8 clang-format
Expand Down
29 changes: 27 additions & 2 deletions autonomy/interfacing/can/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@ find_package(ament_index_cpp REQUIRED) # ROS tool to find shared directories of
find_package(ament_cmake REQUIRED) # ROS2 build tool
find_package(rclcpp REQUIRED) # ROS2 C++ package
find_package(std_msgs REQUIRED) # ROS2 message package
find_package(Boost REQUIRED) # Boost libraries
find_package(yaml-cpp REQUIRED)
find_package(ament_index_cpp REQUIRED)

find_package(common_msgs REQUIRED)

# Compiles source files into a library
# A library is not executed, instead other executables can link
# against it to access defined methods and classes.
# We build a library so that the methods defined can be used by
# both the unit test and ROS2 node executables.

add_library(can_lib
src/can_core.cpp
)

# Indicate to compiler where to search for header files
target_include_directories(can_lib
target_include_directories(can_lib PRIVATE
/usr/local/include
PUBLIC
include
)
Expand All @@ -36,15 +43,22 @@ ament_target_dependencies(can_lib
ament_index_cpp
rclcpp
std_msgs
common_msgs
)

# Link system libraries for CAN support
# Note: Using system CAN libraries instead of libsocketcan for broader compatibility
target_link_libraries(can_lib)

target_link_libraries(can_lib
/usr/local/lib/libdbcppp.so
yaml-cpp
ament_index_cpp::ament_index_cpp
)

# Create the can_node executable
add_executable(can_node src/can_node.cpp src/can_core.cpp)
ament_target_dependencies(can_node rclcpp std_msgs)

# Link to the previously built libraries
target_link_libraries(can_node can_lib)

Expand Down Expand Up @@ -77,4 +91,15 @@ install(TARGETS
test_controller_node
DESTINATION lib/${PROJECT_NAME})

install(
DIRECTORY config/
DESTINATION share/can/config
)

# NOTE: this method of installation is not secure for production env
install(
FILES ../dbc/humanoid.dbc
DESTINATION share/can/config
)

ament_package()
2 changes: 1 addition & 1 deletion autonomy/interfacing/can/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## CAN Interfacing Package Documentation

The documentation for the CAN interfacing package follows a standard WATOnomous package level scheme. As shown below:
The documentation for the CAN interfacing package follows a standard WATonomous package level scheme. As shown below:
```
can/
├── CMakeLists.txt
Expand Down
165 changes: 165 additions & 0 deletions autonomy/interfacing/can/config/hardware_mapping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
left:
shoulder:
pitch:
can_id: 0x01
lower_limit: -90
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
roll:
can_id: 0x02
lower_limit: -90
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
yaw:
can_id: 0x03
lower_limit: -90
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
elbow:
pitch:
can_id: 0x04
lower_limit: -130
upper_limit: 0
direction: 1
zero_offset: 0
limit_range: true
roll:
can_id: 0x05
lower_limit: -130
upper_limit: 0
direction: 1
zero_offset: 0
limit_range: true
wrist:
pitch:
can_id: 0x06
lower_limit: -90
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
gripper:
open_close:
can_id: 0x07
lower_limit: 0
upper_limit: 100
direction: 1
zero_offset: 0
limit_range: true
hand:
pinky:
mcp:
can_id: 0x07
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
pip:
can_id: 0x08
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
dip:
can_id: 0x09
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
ring:
mcp:
can_id: 0x0A
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
pip:
can_id: 0x0B
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
dip:
can_id: 0x0C
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
middle:
mcp:
can_id: 0x0D
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
pip:
can_id: 0x0E
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
dip:
can_id: 0x0F
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
index:
mcp:
can_id: 0x10
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
pip:
can_id: 0x11
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
dip:
can_id: 0x12
lower_limit: 0
upper_limit: 90
direction: 1
zero_offset: 0
limit_range: true
thumb:
cmc:
can_id: 0x13
lower_limit: 0
upper_limit: 60
direction: 1
zero_offset: 0
limit_range: true
mcp:
can_id: 0x14
lower_limit: 0
upper_limit: 70
direction: 1
zero_offset: 0
limit_range: true
ip:
can_id: 0x15
lower_limit: 0
upper_limit: 80
direction: 1
zero_offset: 0
limit_range: true
6 changes: 1 addition & 5 deletions autonomy/interfacing/can/config/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ can_node:

# Communication Settings
publish_rate_hz: 50 # Rate for checking incoming CAN messages
receive_timeout_ms: 10000 # Timeout for receiving CAN messages

# Topics to subscribe to (message types will be auto-detected)
topics:
- "/test_controller"
receive_timeout_ms: 10000 # Timeout for receiving CAN messages
25 changes: 11 additions & 14 deletions autonomy/interfacing/can/include/can_core.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#ifndef CAN_CORE_HPP
#define CAN_CORE_HPP
#pragma once

#include "rclcpp/rclcpp.hpp"
#include <cstdint>
#include <string>
#include <vector>

namespace autonomy {

struct CanMessage {
uint32_t id; // CAN message ID
std::vector<uint8_t> data; // Message data (up to 8 bytes for classic CAN)
uint8_t dlc; // Data Length Code
bool is_extended_id; // Extended frame format flag
bool is_remote_frame; // Remote transmission request flag
uint64_t timestamp_us; // Timestamp in microseconds
CanMessage() {}
CanMessage(int size) : data(size, 0), dlc(size) {}
CanMessage(int id, int size) : id(id), data(size, 0), dlc(size) {}

uint32_t id; // CAN message ID
std::vector<uint8_t> data; // Message data 8 bytes
uint8_t dlc; // Data Length Code
bool is_extended_id = false; // Extended frame format flag
bool is_remote_frame = false; // Remote transmission request flag
uint64_t timestamp_us; // Timestamp in microseconds
};

struct CanConfig {
Expand Down Expand Up @@ -54,7 +55,3 @@ class CanCore {
bool setupSocketCan();
bool setupSlcan();
};

} // namespace autonomy

#endif // CAN_CORE_HPP
Loading
Loading