Reputation: 335
Hi I created some controllers to control a mobile robot. When compile there is no error. Here is my controller launch file.
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory
from launch.substitutions import Command
import os
def generate_launch_description():
# Path to URDF file
urdf_file = os.path.join(get_package_share_directory('localisation_sim_task'), 'urdf', 'load_vehicle.urdf')
# Path to the controllers configuration (params.yaml)
params_file = os.path.join(get_package_share_directory('localisation_sim_task'), 'config', 'params.yaml')
robot_description = Command(['xacro ', urdf_file])
return LaunchDescription([
# Robot state publisher to publish the URDF
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
name='robot_state_publisher',
output='screen',
parameters=[{'robot_description': robot_description}],
),
# Start ros2_control_node with the controllers from params.yaml
Node(
package='controller_manager',
executable='ros2_control_node',
parameters=[params_file],
output='screen',
),
# Load and start the arm position controller
Node(
package='controller_manager',
executable='spawner',
arguments=['arm_position_controller'],
output='screen',
),
# Load and start the shovel position controller
Node(
package='controller_manager',
executable='spawner',
arguments=['shovel_position_controller'],
output='screen',
),
# Start custom node for controlling the arm and shovel
Node(
package='localisation_sim_task',
executable='arm_shovel_controller',
name='arm_shovel_controller',
output='screen',
),
# Start steering velocity controller
Node(
package='localisation_sim_task',
executable='steering_velocity_controller',
name='steering_velocity_controller',
output='screen',
),
])
And here is the cpp file
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/float64.hpp"
class ArmShovelController : public rclcpp::Node {
public:
ArmShovelController() : Node("arm_shovel_controller") {
arm_pub_ = this->create_publisher<std_msgs::msg::Float64>("/arm_position_controller/command", 10);
shovel_pub_ = this->create_publisher<std_msgs::msg::Float64>("/shovel_position_controller/command", 10);
// Publish commands to move the arm and shovel
timer_ = this->create_wall_timer(
std::chrono::milliseconds(100), std::bind(&ArmShovelController::publish_commands, this));
}
private:
void publish_commands() {
auto arm_msg = std_msgs::msg::Float64();
auto shovel_msg = std_msgs::msg::Float64();
// Example positions
arm_msg.data = 0.5; // Example: move the arm to 0.5 radians
shovel_msg.data = 0.2; // Example: move the shovel to 0.2 radians
arm_pub_->publish(arm_msg);
shovel_pub_->publish(shovel_msg);
}
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr arm_pub_;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr shovel_pub_;
rclcpp::TimerBase::SharedPtr timer_;
};
int main(int argc, char **argv) {
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ArmShovelController>());
rclcpp::shutdown();
return 0;
}
and the params.yaml file
arm_position_controller:
ros__parameters:
type: position_controllers/JointPositionController # Define the type of the controller
joint: arm_joint
command_interfaces:
- position
state_interfaces:
- position
- velocity
shovel_position_controller:
ros__parameters:
type: position_controllers/JointPositionController # Define the type of the controller
joint: shovel_joint
command_interfaces:
- position
state_interfaces:
- position
- velocity
steering_velocity_controller:
ros__parameters:
type: velocity_controllers/JointVelocityController # Define the type of the controller
joint: steering_joint
command_interfaces:
- velocity
state_interfaces:
- velocity
when run
ros2 param list /controller_manager
qos_overrides./parameter_events.publisher.depth
qos_overrides./parameter_events.publisher.durability
qos_overrides./parameter_events.publisher.history
qos_overrides./parameter_events.publisher.reliability use_sim_time
It seems that the
/controller_manager
node is running, but it doesn’t have any parameters related to the controllers themselves. Normally, you should see parameters like arm_position_controller, shovel_position_controller, etc., listed under /controller_manager
what can be the problem and how to fix it?
Upvotes: 1
Views: 28