Skip to content

Commit 5090be7

Browse files
committed
finished hardware interface refactor
1 parent a1b9ddf commit 5090be7

27 files changed

Lines changed: 1077 additions & 2225 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ qtcreator-*
5656
# Glade temp file
5757
#*.glade*
5858

59+
#other hmi things
60+
src/rover_hmi_v2
61+
5962
# Catkin custom files
6063
CATKIN_IGNORE
6164
install/

src/arm_hardware_interface/CMakeLists.txt

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,34 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
55
add_compile_options(-Wall -Wextra -Wpedantic)
66
endif()
77

8-
# find dependencies
98
find_package(ament_cmake REQUIRED)
109
find_package(rclcpp REQUIRED)
11-
find_package(sensor_msgs REQUIRED)
12-
find_package(serial REQUIRED)
1310
find_package(rover_msgs REQUIRED)
14-
find_package(arm_control REQUIRED)
1511
find_package(std_msgs REQUIRED)
16-
# uncomment the following section in order to fill in further dependencies
17-
# manually. find_package(<dependency> REQUIRED)
18-
include_directories(include ${arm_control_INCLUDE_DIRS})
19-
20-
add_subdirectory(moteus)
21-
add_library(${PROJECT_NAME} src/armprotocol.cpp
22-
include/arm_hardware_interface/ArmSerialProtocol.h)
12+
find_package(sensor_msgs REQUIRED)
2313

24-
# For old and new arm
25-
add_executable(
26-
serial_arm_driver src/ArmSerialInterface.cpp include/ArmSerialInterface.h
27-
include/arm_hardware_interface/ArmSerialProtocol.h)
28-
add_executable(
29-
moteus_arm_driver
30-
src/moteus_CAN_interface/MoteusMain.cpp
31-
src/moteus_CAN_interface/MoteusNode.cpp
32-
src/moteus_CAN_interface/CommandCallback.cpp
33-
src/moteus_CAN_interface/MoteusInterface.cpp
34-
src/moteus_CAN_interface/MoteusIO.cpp)
14+
include_directories(include)
3515

36-
target_compile_definitions(moteus_arm_driver PRIVATE BUILDING_NEW_DRIVER=1) #??
16+
add_subdirectory(moteus)
3717

38-
target_link_libraries(moteus_arm_driver moteus::cpp)
39-
ament_target_dependencies(serial_arm_driver rclcpp sensor_msgs serial
40-
rover_msgs arm_control)
41-
ament_target_dependencies(moteus_arm_driver rclcpp sensor_msgs serial
42-
rover_msgs arm_control std_msgs)
18+
add_executable(moteus_driver src/moteus_driver_node.cpp)
19+
target_link_libraries(moteus_driver moteus::cpp)
20+
ament_target_dependencies(moteus_driver rclcpp rover_msgs std_msgs sensor_msgs)
4321

4422
if(BUILD_TESTING)
4523
find_package(ament_lint_auto REQUIRED)
46-
# the following line skips the linter which checks for copyrights comment the
47-
# line when a copyright and license is added to all source files
4824
set(ament_cmake_copyright_FOUND TRUE)
49-
# the following line skips cpplint (only works in a git repo) comment the line
50-
# when this package is in a git repo and when a copyright and license is added
51-
# to all source files
5225
set(ament_cmake_cpplint_FOUND TRUE)
5326
ament_lint_auto_find_test_dependencies()
5427
endif()
55-
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}/launch)
5628

57-
# Install headers for other packages (for arm serial protocol)
29+
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}/launch)
5830
install(DIRECTORY include/ DESTINATION include/)
5931

6032
install(
61-
TARGETS serial_arm_driver moteus_arm_driver ${PROJECT_NAME}
62-
DESTINATION lib/${PROJECT_NAME}
63-
ARCHIVE DESTINATION lib
64-
LIBRARY DESTINATION lib)
33+
TARGETS moteus_driver
34+
DESTINATION lib/${PROJECT_NAME})
6535

6636
ament_export_include_directories(include)
67-
ament_export_libraries(${PROJECT_NAME})
6837

69-
ament_package()
38+
ament_package()

src/arm_hardware_interface/include/ArmMoteusInterface.h

Lines changed: 0 additions & 145 deletions
This file was deleted.

src/arm_hardware_interface/include/ArmSerialInterface.h

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#pragma once
2+
3+
#include <cmath> // NAN
4+
5+
// =============================================================================
6+
// Arm Command Types (arm_commands.h)
7+
// =============================================================================
8+
//
9+
// This file defines what commands the ROS layer can send to the driver and
10+
// how those commands are stored internally while they wait to be sent on the
11+
// CAN bus.
12+
//
13+
// Flow:
14+
// /arm/command topic → commandCallback() → pending_cmds_[]
15+
// → (next poll tick) → active_cmds_[]
16+
// → CAN frame via moteus_protocol.h
17+
//
18+
// Why two arrays (pending / active)?
19+
// The moteus controller has a watchdog: if it stops receiving valid CAN
20+
// frames it will fault (fault code 32 = timeout). active_cmds_ is
21+
// re-sent every poll cycle so the watchdog never fires, even if the ROS
22+
// topic goes quiet. pending_cmds_ just holds the latest user intent
23+
// until the next poll tick picks it up.
24+
// =============================================================================
25+
26+
27+
// -----------------------------------------------------------------------------
28+
// Command codes — carried in rover_msgs::msg::ArmCommand::cmd_type
29+
// -----------------------------------------------------------------------------
30+
31+
// Stop all motors immediately.
32+
// - Motor enters kStopped mode → no torque, no position hold (goes limp).
33+
// - Always accepted, even when a fault is active.
34+
// - Clears fault-blocking so motion commands can resume afterwards.
35+
constexpr char CMD_STOP = 'S';
36+
37+
// Absolute position command.
38+
// positions[] = target output-shaft revolutions for each motor (NaN = skip that motor)
39+
// velocities[] = optional velocity feed-forward in rev/s (NaN = use motion profile)
40+
// Blocked if the target motor has an active fault — send CMD_STOP first.
41+
constexpr char CMD_ABS_POS = 'P';
42+
43+
// Velocity command (jog mode — hold the button to move).
44+
// velocities[] = target output-shaft rev/s for each motor (NaN = skip that motor)
45+
// A velocity of exactly 0.0 is treated as CMD_STOP for that motor
46+
// (motor goes limp, not hold-position), matching the jog-button release behaviour.
47+
constexpr char CMD_ABS_VEL = 'V';
48+
49+
// Zero (re-home) command — equivalent to "d exact 0" in tview.
50+
// Resets the position counter to 0.0 at the current physical position.
51+
// The motor does NOT move — only the position reference is updated.
52+
// Use this to establish a new zero point after manually positioning the arm.
53+
// positions[] used as a flag: any non-NaN entry means "zero that motor".
54+
constexpr char CMD_ZERO = 'Z';
55+
56+
57+
// -----------------------------------------------------------------------------
58+
// Internal command state — one slot per motor
59+
// -----------------------------------------------------------------------------
60+
61+
// Represents one pending or active motion instruction for a single motor.
62+
// Stored in MoteusDriverNode::pending_cmds_[] and active_cmds_[].
63+
struct MotorCommand {
64+
bool active = false; // true → there is something to send this cycle
65+
bool is_stop = false; // true → send MakeStop; overrides everything
66+
bool is_zero = false; // true → send "d exact 0" (re-home in place); one-shot
67+
double position = 0.0; // output-shaft revolutions (NaN = no position target)
68+
double velocity = 0.0; // output-shaft rev/s (NaN = use motion profile)
69+
double max_torque = NAN; // N·m output-shaft cap (NaN = firmware default)
70+
};

0 commit comments

Comments
 (0)