7 Commits

Author SHA1 Message Date
X-lanni 23491dad2e update agv_pro_base/src/agv_pro_ros.cpp 2025-06-22 18:26:40 +08:00
X-lanni c7a3545186 update agv_pro_bringup/launch/agv_pro_bringup.launch.py 2025-06-22 16:28:23 +08:00
X-lanni 0d610a89bb bump agv_pro_description to 1.0.1 2025-06-22 16:22:25 +08:00
X-lanni 90d7bde0e3 Fix the issue of odom publishing time being out of sync 2025-06-21 17:32:53 +08:00
X-lanni 6ef6e50cc8 Add a namespace for multi-machine control 2025-06-21 15:33:35 +08:00
X-lanni b20f5a4faa add agvpro_display.rviz 2025-06-19 10:15:13 +08:00
X-lanni 9cc3814cc4 bump agv_pro_base to 1.0.1 2025-06-18 11:45:46 +08:00
9 changed files with 377 additions and 60 deletions
@@ -39,8 +39,6 @@ private:
std::string name_space_;
std::string device_name_;
std::thread control_thread_;
double x= 0.0;
double y= 0.0;
double theta= 0.0;
@@ -60,6 +58,7 @@ private:
float battery_voltage = 0.0f;
rclcpp::Time currentTime, lastTime;
rclcpp::TimerBase::SharedPtr control_timer_;
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr pub_odom;
rclcpp::Publisher<sensor_msgs::msg::Imu>::SharedPtr pub_imu;
rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr pub_voltage;
+1 -1
View File
@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>agv_pro_base</name>
<version>1.0.0</version>
<version>1.0.2</version>
<description>Control Nodes for AGV Pro</description>
<maintainer email="weijun.xie@elephantrobotics.com">lanni</maintainer>
<license>BSD-3-Clause license</license>
+28 -21
View File
@@ -197,14 +197,7 @@ void AGV_PRO::publisherVoltage()
void AGV_PRO::publisherOdom(double dt)
{
geometry_msgs::msg::TransformStamped odom_trans;
odom_trans.header.stamp = this->get_clock()->now();
odom_trans.header.frame_id = "odom";
odom_trans.child_frame_id = "base_footprint";
tf2::Quaternion quat;
quat.setRPY(0.0, 0.0, theta);
geometry_msgs::msg::Quaternion odom_quat = tf2::toMsg(quat);
currentTime = this->get_clock()->now();
double delta_x = (vx * cos(theta) - vy * sin(theta)) * dt;
double delta_y = (vx * sin(theta) + vy * cos(theta)) * dt;
@@ -214,18 +207,26 @@ void AGV_PRO::publisherOdom(double dt)
y += delta_y;
theta += delta_th;
geometry_msgs::msg::TransformStamped odom_trans;
odom_trans.header.stamp = currentTime;
odom_trans.header.frame_id = frame_id_of_odometry_;
odom_trans.child_frame_id = child_frame_id_of_odometry_;
tf2::Quaternion quat;
quat.setRPY(0.0, 0.0, theta);
geometry_msgs::msg::Quaternion odom_quat = tf2::toMsg(quat);
odom_trans.transform.translation.x = x;
odom_trans.transform.translation.y = y;
odom_trans.transform.translation.z = 0.0;
odom_trans.transform.rotation = odom_quat;
odomBroadcaster->sendTransform(odom_trans);
nav_msgs::msg::Odometry odom;
odom.header.stamp = this->get_clock()->now();;
odom.header.frame_id = "odom";
odom.child_frame_id = "base_footprint";
odom.header.stamp = currentTime;
odom.header.frame_id = frame_id_of_odometry_;
odom.child_frame_id = child_frame_id_of_odometry_;
odom.pose.pose.position.x = x;
odom.pose.pose.position.y = y;
@@ -243,18 +244,18 @@ void AGV_PRO::publisherOdom(double dt)
void AGV_PRO::Control()
{
lastTime = this->get_clock()->now();
while(rclcpp::ok())
{
currentTime = this->get_clock()->now();
double dt = (currentTime - lastTime).seconds();
if (true == readData())
{
publisherOdom(dt);
//RCLCPP_INFO(this->get_logger(), "dt:%f", dt);
publisherVoltage();
currentTime = this->get_clock()->now();
double dt = 0.0;
if (lastTime.nanoseconds() != 0) {
dt = (currentTime - lastTime).seconds();
}
lastTime = currentTime;
publisherOdom(dt);
// RCLCPP_INFO(this->get_logger(), "dt:%f", dt);
publisherVoltage();
}
}
@@ -285,6 +286,8 @@ AGV_PRO::AGV_PRO(std::string node_name):rclcpp::Node(node_name)
cmd_sub = this->create_subscription<geometry_msgs::msg::Twist>(
"/cmd_vel", 10, std::bind(&AGV_PRO::cmdCallback, this, std::placeholders::_1));
lastTime = this->get_clock()->now();
drivers::serial_driver::SerialPortConfig config(
1000000,
drivers::serial_driver::FlowControl::NONE,
@@ -309,7 +312,11 @@ AGV_PRO::AGV_PRO(std::string node_name):rclcpp::Node(node_name)
return;
}
control_thread_ = std::thread(&AGV_PRO::Control, this);
control_timer_ = this->create_wall_timer(
std::chrono::milliseconds(20),
std::bind(&AGV_PRO::Control, this)
);
}
AGV_PRO::~AGV_PRO()
@@ -1,8 +1,8 @@
import os
from launch import LaunchDescription
from launch_ros.actions import Node
from launch_ros.actions import Node,PushRosNamespace
from launch.actions import DeclareLaunchArgument,IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.substitutions import Command,LaunchConfiguration,PythonExpression
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
@@ -17,8 +17,12 @@ def generate_launch_description():
'agv_pro.urdf'
)
with open(urdf_file, 'r') as file:
robot_description_content = file.read()
robot_description_content = Command([
'xacro ',
urdf_file,
' namespace:=',
PythonExpression(['"', namespace, '" + "/" if "', namespace, '" != "" else ""']),
])
return LaunchDescription([
DeclareLaunchArgument(
@@ -26,6 +30,13 @@ def generate_launch_description():
default_value=port_name_arg,
description='port name, e.g. ttyACM0'),
DeclareLaunchArgument(
'namespace',
default_value='',
description='Namespace for nodes'),
PushRosNamespace(namespace),
Node(
package='agv_pro_base',
executable='agv_pro_node',
@@ -35,6 +46,7 @@ def generate_launch_description():
'port_name': port_name_arg,
'namespace': namespace,
}],
remappings=[('cmd_vel', '/cmd_vel')]
),
Node(
@@ -47,7 +59,8 @@ def generate_launch_description():
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
parameters=[{'robot_description': robot_description_content}]
parameters=[{'robot_description': robot_description_content}],
output='screen'
),
IncludeLaunchDescription(
+1 -1
View File
@@ -14,7 +14,7 @@ if(BUILD_TESTING)
ament_lint_auto_find_test_dependencies()
endif()
install(DIRECTORY meshes urdf
install(DIRECTORY meshes urdf launch rviz
DESTINATION share/${PROJECT_NAME}
)
@@ -0,0 +1,63 @@
import os
from launch import LaunchDescription
from launch_ros.actions import Node,PushRosNamespace
from launch.conditions import IfCondition
from launch.actions import DeclareLaunchArgument
from launch.substitutions import Command,LaunchConfiguration,PythonExpression
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
namespace = LaunchConfiguration('namespace', default='')
use_rviz = LaunchConfiguration('use_rviz', default='true')
rviz_config_dir = os.path.join(
get_package_share_directory('agv_pro_description'),
'rviz',
'agvpro_display.rviz')
urdf_file = os.path.join(
get_package_share_directory('agv_pro_description'),
'urdf',
'agv_pro.urdf'
)
robot_description_content = Command([
'xacro ',
urdf_file,
' namespace:=',
PythonExpression(['"', namespace, '" + "/" if "', namespace, '" != "" else ""']),
])
return LaunchDescription([
DeclareLaunchArgument(
'namespace',
default_value='',
description='Namespace for nodes'),
PushRosNamespace(namespace),
Node(
package='joint_state_publisher',
executable='joint_state_publisher',
name='joint_state_publisher'
),
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
parameters=[{'robot_description': robot_description_content}]
),
Node(
package='rviz2',
executable='rviz2',
name='rviz2',
arguments=['-d', rviz_config_dir],
condition=IfCondition(use_rviz),
output='screen')
])
+1 -1
View File
@@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>agv_pro_description</name>
<version>1.0.0</version>
<version>1.0.1</version>
<description>
<p>URDF Description package for AGV pro</p>
</description>
@@ -0,0 +1,234 @@
Panels:
- Class: rviz_common/Displays
Help Height: 78
Name: Displays
Property Tree Widget:
Expanded:
- /Global Options1
- /Status1
- /RobotModel1
- /TF1
Splitter Ratio: 0.5
Tree Height: 549
- Class: rviz_common/Selection
Name: Selection
- Class: rviz_common/Tool Properties
Expanded:
- /2D Goal Pose1
- /Publish Point1
Name: Tool Properties
Splitter Ratio: 0.5886790156364441
- Class: rviz_common/Views
Expanded:
- /Current View1
Name: Views
Splitter Ratio: 0.5
- Class: rviz_common/Time
Experimental: false
Name: Time
SyncMode: 0
SyncSource: ""
Visualization Manager:
Class: ""
Displays:
- Alpha: 0.5
Cell Size: 1
Class: rviz_default_plugins/Grid
Color: 160; 160; 164
Enabled: true
Line Style:
Line Width: 0.029999999329447746
Value: Lines
Name: Grid
Normal Cell Count: 0
Offset:
X: 0
Y: 0
Z: 0
Plane: XY
Plane Cell Count: 10
Reference Frame: <Fixed Frame>
Value: true
- Alpha: 1
Class: rviz_default_plugins/RobotModel
Collision Enabled: false
Description File: ""
Description Source: Topic
Description Topic:
Depth: 5
Durability Policy: Volatile
History Policy: Keep Last
Reliability Policy: Reliable
Value: /robot_description
Enabled: true
Links:
All Links Enabled: true
Expand Joint Details: false
Expand Link Details: false
Expand Tree: false
Link Tree Style: Links in Alphabetic Order
base_footprint:
Alpha: 1
Show Axes: false
Show Trail: false
base_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
laser_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
left_front_wheel_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
left_rear_wheel_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
right_front_wheel_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
right_rear_wheel_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
Mass Properties:
Inertia: false
Mass: false
Name: RobotModel
TF Prefix: ""
Update Interval: 0
Value: true
Visual Enabled: true
- Class: rviz_default_plugins/TF
Enabled: true
Frame Timeout: 15
Frames:
All Enabled: true
base_footprint:
Value: true
base_link:
Value: true
laser_link:
Value: true
left_front_wheel_link:
Value: true
left_rear_wheel_link:
Value: true
right_front_wheel_link:
Value: true
right_rear_wheel_link:
Value: true
Marker Scale: 1
Name: TF
Show Arrows: true
Show Axes: true
Show Names: false
Tree:
base_footprint:
base_link:
laser_link:
{}
left_front_wheel_link:
{}
left_rear_wheel_link:
{}
right_front_wheel_link:
{}
right_rear_wheel_link:
{}
Update Interval: 0
Value: true
Enabled: true
Global Options:
Background Color: 48; 48; 48
Fixed Frame: base_footprint
Frame Rate: 30
Name: root
Tools:
- Class: rviz_default_plugins/Interact
Hide Inactive Objects: true
- Class: rviz_default_plugins/MoveCamera
- Class: rviz_default_plugins/Select
- Class: rviz_default_plugins/FocusCamera
- Class: rviz_default_plugins/Measure
Line color: 128; 128; 0
- Class: rviz_default_plugins/SetInitialPose
Covariance x: 0.25
Covariance y: 0.25
Covariance yaw: 0.06853891909122467
Topic:
Depth: 5
Durability Policy: Volatile
History Policy: Keep Last
Reliability Policy: Reliable
Value: /initialpose
- Class: rviz_default_plugins/SetGoal
Topic:
Depth: 5
Durability Policy: Volatile
History Policy: Keep Last
Reliability Policy: Reliable
Value: /goal_pose
- Class: rviz_default_plugins/PublishPoint
Single click: true
Topic:
Depth: 5
Durability Policy: Volatile
History Policy: Keep Last
Reliability Policy: Reliable
Value: /clicked_point
Transformation:
Current:
Class: rviz_default_plugins/TF
Value: true
Views:
Current:
Class: rviz_default_plugins/Orbit
Distance: 1.6701574325561523
Enable Stereo Rendering:
Stereo Eye Separation: 0.05999999865889549
Stereo Focal Distance: 1
Swap Stereo Eyes: false
Value: false
Focal Point:
X: 0
Y: 0
Z: 0
Focal Shape Fixed Size: true
Focal Shape Size: 0.05000000074505806
Invert Z Axis: false
Name: Current View
Near Clip Distance: 0.009999999776482582
Pitch: 0.785398006439209
Target Frame: <Fixed Frame>
Value: Orbit (rviz)
Yaw: 0.785398006439209
Saved: ~
Window Geometry:
Displays:
collapsed: false
Height: 846
Hide Left Dock: false
Hide Right Dock: true
QMainWindow State: 000000ff00000000fd000000040000000000000156000002b0fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000002b0000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002b0fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000003d000002b0000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004b00000003efc0100000002fb0000000800540069006d00650100000000000004b0000002fb00fffffffb0000000800540069006d0065010000000000000450000000000000000000000354000002b000000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
Selection:
collapsed: false
Time:
collapsed: false
Tool Properties:
collapsed: false
Views:
collapsed: true
Width: 1200
X: 720
Y: 343
+29 -28
View File
@@ -1,15 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<robot name="AGV pro" xmlns:xacro="http://www.ros.org/wiki/xacro">
<link name="base_footprint"/>
<xacro:arg name="namespace" default=""/>
<xacro:property name="namespace" value="$(arg namespace)"/>
<joint name="base_joint" type="fixed">
<parent link="base_footprint"/>
<child link="base_link" />
<link name="${namespace}base_footprint"/>
<joint name="${namespace}base_joint" type="fixed">
<parent link="${namespace}base_footprint"/>
<child link="${namespace}base_link" />
<origin xyz="0 0 0.020" rpy="0 0 0"/>
</joint>
<link name="base_link">
<link name="${namespace}base_link">
<inertial>
<origin xyz="-0.0076254 -0.00023134 0.06693" rpy="0 0 0" />
<mass value="19.236" />
@@ -37,7 +40,7 @@
</collision>
</link>
<link name="right_rear_wheel_link">
<link name="${namespace}right_rear_wheel_link">
<inertial>
<origin xyz="0 0 0" rpy="0 0 0" />
<mass value="0.21659" />
@@ -66,14 +69,14 @@
</collision>
</link>
<joint name="right_rear_wheel_joint" type="continuous">
<joint name="${namespace}right_rear_wheel_joint" type="continuous">
<origin xyz="-0.171806101587598 -0.179900399999999 0.0518836514526621" rpy="0 0 0" />
<parent link="base_link" />
<child link="right_rear_wheel_link" />
<parent link="${namespace}base_link" />
<child link="${namespace}right_rear_wheel_link" />
<axis xyz="0 1 0" />
</joint>
<link name="right_front_wheel_link">
<link name="${namespace}right_front_wheel_link">
<inertial>
<origin xyz="6.6563E-05 -0.019725 8.3836E-05" rpy="0 0 0" />
<mass value="0.21659122149244" />
@@ -100,15 +103,15 @@
</collision>
</link>
<joint name="right_front_wheel_joint" type="continuous">
<joint name="${namespace}right_front_wheel_joint" type="continuous">
<origin xyz="-0.17181 0.1799 0.051884"
rpy="0 0 0" />
<parent link="base_link" />
<child link="right_front_wheel_link" />
<parent link="${namespace}base_link" />
<child link="${namespace}right_front_wheel_link" />
<axis xyz="0 1 0" />
</joint>
<link name="left_front_wheel_link">
<link name="${namespace}left_front_wheel_link">
<inertial>
<origin xyz="1.4671E-06 -0.019803 4.3218E-06" rpy="0 0 0" />
<mass value="0.3015" />
@@ -135,15 +138,15 @@
</collision>
</link>
<joint name="left_front_wheel_joint" type="continuous">
<joint name="${namespace}left_front_wheel_joint" type="continuous">
<origin xyz="0.17128 0.1799 0.052"
rpy="0 0 0" />
<parent link="base_link" />
<child link="left_front_wheel_link" />
<parent link="${namespace}base_link" />
<child link="${namespace}left_front_wheel_link" />
<axis xyz="0 1 0" />
</joint>
<link name="left_rear_wheel_link">
<link name="${namespace}left_rear_wheel_link">
<inertial>
<origin xyz="-2.4454E-06 0.019725 -4.3121E-06" rpy="0 0 0" />
<mass value="0.29613" />
@@ -170,14 +173,14 @@
</collision>
</link>
<joint name="left_rear_wheel_joint" type="continuous">
<joint name="${namespace}left_rear_wheel_joint" type="continuous">
<origin xyz="0.17128 -0.1799 0.052" rpy="0 0 0" />
<parent link="base_link" />
<child link="left_rear_wheel_link" />
<parent link="${namespace}base_link" />
<child link="${namespace}left_rear_wheel_link" />
<axis xyz="0 1 0" />
</joint>
<link name="laser_link">
<link name="${namespace}laser_link">
<inertial>
<origin xyz="-0.0035142 -2.8248E-05 0.0010013" rpy="0 0 0" />
<mass value="0.049095" />
@@ -204,11 +207,9 @@
</collision>
</link>
<joint name="lidar_joint" type="fixed">
<origin xyz="0.17891 0 0.20928"
rpy="0 0 0" />
<parent link="base_link" />
<child link="laser_link" />
<axis xyz="0 0 0" />
<joint name="${namespace}lidar_joint" type="fixed">
<origin xyz="0.17891 0 0.20928" rpy="0 0 0" />
<parent link="${namespace}base_link" />
<child link="${namespace}laser_link" />
</joint>
</robot>