|
1 | | -#include <rclcpp/rclcpp.hpp> |
2 | | -#include "sensor_msgs/msg/joy.hpp" |
3 | | -#include "sensor_msgs/msg/joint_state.hpp" |
4 | 1 | #include "arm_control/include/armControlParams.h" |
| 2 | +#include "sensor_msgs/msg/joint_state.hpp" |
| 3 | +#include "sensor_msgs/msg/joy.hpp" |
| 4 | +#include <rclcpp/rclcpp.hpp> |
5 | 5 |
|
6 | 6 | #include "rover_msgs/msg/arm_command.hpp" |
7 | | -#include <thread> |
8 | 7 | #include <chrono> |
| 8 | +#include <thread> |
9 | 9 |
|
| 10 | +#ifdef BUILDING_NEW_DRIVER |
10 | 11 | #include "moteus.h" |
11 | | -#include <arm_hardware_interface/ArmSerialProtocol.h> |
| 12 | +using namespace mjbots; |
| 13 | +#endif |
12 | 14 |
|
| 15 | +#include <arm_hardware_interface/ArmSerialProtocol.h> |
13 | 16 |
|
14 | 17 | #include <serial/serial.h> |
15 | 18 |
|
|
22 | 25 | #define AXIS_1_DIR 1 |
23 | 26 | #define AXIS_2_DIR 1 |
24 | 27 | #define AXIS_3_DIR 1 |
25 | | -#define AXIS_4_DIR 1 |
| 28 | +#define AXIS_4_DIR 1 |
26 | 29 | #define AXIS_5_DIR 1 |
27 | 30 | #define AXIS_6_DIR 1 |
28 | 31 |
|
29 | 32 | using std::string; |
30 | | -using namespace mjbots; |
31 | 33 |
|
32 | 34 | class ArmSerial : public rclcpp::Node { |
33 | 35 | public: |
34 | | - ArmSerial(); |
35 | | - |
36 | | - // float firm |
| 36 | + ArmSerial(); |
37 | 37 |
|
38 | | - rover_msgs::msg::ArmCommand current_arm_status; |
| 38 | + // float firm |
39 | 39 |
|
40 | | - // angle_echo.positions.resize(NUM_JOINTS); |
41 | | - // void start_rx() { |
42 | | - // serialRxThread = std::thread(&ArmSerial::serial_rx(), this); |
43 | | - // } |
44 | | - // string joint_names[6] = {"joint_turntable", "joint_axis1", "joint_axis2", "joint_axis3", "joint_axis4", "joint_ender"}; //? old arm urdf |
45 | | - string joint_names[NUM_JOINTS + 2] = {"joint_1", "joint_2", "joint_3", "joint_4", "joint_5", "joint_6", "finger_left_joint", "finger_right_joint"}; //? newest (Sep 2024) arm urdf |
| 40 | + rover_msgs::msg::ArmCommand current_arm_status; |
46 | 41 |
|
| 42 | + // angle_echo.positions.resize(NUM_JOINTS); |
| 43 | + // void start_rx() { |
| 44 | + // serialRxThread = std::thread(&ArmSerial::serial_rx(), this); |
| 45 | + // } |
| 46 | + // string joint_names[6] = {"joint_turntable", "joint_axis1", "joint_axis2", "joint_axis3", "joint_axis4", "joint_ender"}; //? old arm |
| 47 | + // urdf |
| 48 | + string joint_names[NUM_JOINTS + 2] = {"joint_1", "joint_2", "joint_3", "joint_4", |
| 49 | + "joint_5", "joint_6", "finger_left_joint", "finger_right_joint"}; //? newest (Sep 2024) arm urdf |
47 | 50 |
|
48 | 51 | private: |
| 52 | + unsigned long baud = 115200; // 19200; |
| 53 | + string port = "/dev/serial/by-id/usb-ZEPHYR_UBC_ROVER_Arm_500100C6224069D7-if00"; |
49 | 54 |
|
50 | | - unsigned long baud = 115200;//19200; |
51 | | - string port = "/dev/serial/by-id/usb-ZEPHYR_UBC_ROVER_Arm_500100C6224069D7-if00"; |
52 | | - |
53 | | - serial::Serial teensy; |
54 | | - serial::Timeout timeout_uart = serial::Timeout::simpleTimeout(1000); // E.g., 1000 ms or 1 second |
55 | | - |
| 55 | + serial::Serial teensy; |
| 56 | + serial::Timeout timeout_uart = serial::Timeout::simpleTimeout(1000); // E.g., 1000 ms or 1 second |
56 | 57 |
|
| 58 | +#ifdef BUILDING_NEW_DRIVER |
57 | 59 | std::map<int, std::shared_ptr<moteus::Controller>> controllers; |
58 | 60 | std::map<int, moteus::Query::Result> servo_data; |
59 | 61 | std::shared_ptr<moteus::Transport> transport; |
60 | | - bool send_angles = true; |
61 | | - |
62 | | - struct Axis{ |
63 | | - float curr_pos; |
64 | | - float target_pos; |
65 | | - float speed; |
66 | | - float zero_rad; |
67 | | - float max_rad; |
68 | | - int dir; |
69 | | - }; |
70 | | - |
71 | | - Axis axes[NUM_JOINTS]; |
72 | | - // Axis axis_EE; |
73 | | - |
74 | | - float target_position[NUM_JOINTS]; |
75 | | - float target_velocities[NUM_JOINTS]; |
76 | | - |
77 | | - int homed = 0; |
78 | | - bool homing = false; |
79 | | - float EE = 0; |
80 | | - volatile float current_velocity[NUM_JOINTS] = {00.00, 00.00, 00.00, 00.00, 00.00, 00.00, 00.00}; |
81 | | - volatile float current_position[NUM_JOINTS] = {00.00, 00.00, 00.00, 00.00, 00.00, 00.00, 00.00}; |
82 | | - volatile int current_limit_switches[NUM_JOINTS] = {-1, -1, -1, -1, -1, -1, -1}; |
83 | | - |
84 | | - rclcpp::Subscription<rover_msgs::msg::ArmCommand>::SharedPtr command_subscriber; |
85 | | - void CommandCallback(const rover_msgs::msg::ArmCommand::SharedPtr msg); |
86 | | - |
87 | | - rclcpp::Publisher<sensor_msgs::msg::JointState>::SharedPtr joint_state_publisher_; |
88 | | - |
89 | | - sensor_msgs::msg::JointState prev_joint_states; //for sim |
90 | | - rclcpp::Publisher<rover_msgs::msg::ArmCommand>::SharedPtr arm_position_publisher; |
91 | | - |
92 | | - rclcpp::TimerBase::SharedPtr timer_; |
93 | | - |
94 | | - std::thread serialRxThread; |
95 | | - |
96 | | - void serial_rx(); //? should be static inline? |
97 | | - float degToRad(float deg); |
98 | | - float firmToMoveitOffsetPos(float deg, int axis); |
99 | | - float firmToMoveitOffsetVel(float deg, int axis); |
100 | | - void send_position_command(float pos[NUM_JOINTS]); |
101 | | - void send_velocity_command(float vel[NUM_JOINTS]); |
102 | | - void send_test_limits_command(); |
103 | | - void sendHomeCmd(int target_axis); |
104 | | - void sendCommCmd(int target_state); |
105 | | - void sendMsg(std::string outMsg); |
106 | | - void parseArmAngleUart(std::string msg); |
107 | | - void parseLimitSwitchTest(std::string msg); |
| 62 | +#endif |
| 63 | + bool send_angles = true; |
| 64 | + |
| 65 | + struct Axis { |
| 66 | + float curr_pos; |
| 67 | + float target_pos; |
| 68 | + float speed; |
| 69 | + float zero_rad; |
| 70 | + float max_rad; |
| 71 | + int dir; |
108 | 72 | }; |
109 | | - |
110 | 73 |
|
| 74 | + Axis axes[NUM_JOINTS]; |
| 75 | + // Axis axis_EE; |
| 76 | + |
| 77 | + float target_position[NUM_JOINTS]; |
| 78 | + float target_velocities[NUM_JOINTS]; |
| 79 | + |
| 80 | + int homed = 0; |
| 81 | + bool homing = false; |
| 82 | + float EE = 0; |
| 83 | + volatile float current_velocity[NUM_JOINTS] = {00.00, 00.00, 00.00, 00.00, 00.00, 00.00, 00.00}; |
| 84 | + volatile float current_position[NUM_JOINTS] = {00.00, 00.00, 00.00, 00.00, 00.00, 00.00, 00.00}; |
| 85 | + volatile int current_limit_switches[NUM_JOINTS] = {-1, -1, -1, -1, -1, -1, -1}; |
| 86 | + |
| 87 | + rclcpp::Subscription<rover_msgs::msg::ArmCommand>::SharedPtr command_subscriber; |
| 88 | + void CommandCallback(const rover_msgs::msg::ArmCommand::SharedPtr msg); |
| 89 | + |
| 90 | + rclcpp::Publisher<sensor_msgs::msg::JointState>::SharedPtr joint_state_publisher_; |
| 91 | + |
| 92 | + sensor_msgs::msg::JointState prev_joint_states; // for sim |
| 93 | + rclcpp::Publisher<rover_msgs::msg::ArmCommand>::SharedPtr arm_position_publisher; |
| 94 | + |
| 95 | + rclcpp::TimerBase::SharedPtr timer_; |
111 | 96 |
|
| 97 | + std::thread serialRxThread; |
112 | 98 |
|
| 99 | + void serial_rx(); //? should be static inline? |
| 100 | + float degToRad(float deg); |
| 101 | + float firmToMoveitOffsetPos(float deg, int axis); |
| 102 | + float firmToMoveitOffsetVel(float deg, int axis); |
| 103 | + void send_position_command(float pos[NUM_JOINTS]); |
| 104 | + void send_velocity_command(float vel[NUM_JOINTS]); |
| 105 | + void send_test_limits_command(); |
| 106 | + void sendHomeCmd(int target_axis); |
| 107 | + void sendCommCmd(int target_state); |
| 108 | + void sendMsg(std::string outMsg); |
| 109 | + void parseArmAngleUart(std::string msg); |
| 110 | + void parseLimitSwitchTest(std::string msg); |
| 111 | +}; |
0 commit comments