0
$\begingroup$

HI everyone i have the following code:

<!--///////////////////////////AUFBAU DES FÖRDERBANDES///////////////////////////////////-->

<!--link name="root_link"/>
<joint name="root_joint" type="fixed">
    <origin xyz="1 0 0.035" rpy="0 0 0"/>
    <parent link="root_link"/>
    <child link="belt"/>
</joint-->

<link name="belt">
    <visual>
        <origin xyz="0 0 0.0" rpy="0 0 0" />
        <geometry>
            <box size="0.5 3 0.15" />
        </geometry>
        <material name="belt">
            <color rgba="0.3 0.3 0.3 1" />
        </material>
    </visual>
    <inertial>
        <origin xyz="0.4 0 0.0" rpy="0 0 0" />
        <mass value="50"/>
        <inertia ixx="${(50/12)*(0.15*0.15+0.5*0.5)}" ixy="0.0" ixz="0.0" iyy="${(50/12)*(3*3+0.5*0.5)}" iyz="0.0" izz="${(50/12)*(0.5*0.5+0.15*0.15)}"/>
    </inertial>

    <collision>
        <origin xyz="0.4 0 0.0" rpy="0 0 0" />
        <geometry>
            <box size="0.5 3 0.15" />
        </geometry>
    </collision>
</link>


<link name="cube">
    <visual>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
            <box size="0.1 0.1 0.1"/>
        </geometry>
        <material name="belt">
            <color rgba="0.5 1.0 0.5 1" />
        </material>
    </visual>
    <inertial>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <mass value="0.05"/>
        <inertia ixx="10" ixy="0.0" ixz="0.0" iyy="10" iyz="0.0" izz="10"/>
    </inertial>
    <collision>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
            <box size="0.1 0.1 0.1"/>
        </geometry>
    </collision>
</link>



<joint name="BeltPrismatic" type="planar">
    <origin xyz="0 -1 0.16" rpy="0 0 0" />
    <parent link="belt" />
    <child link="cube" />
    <axis xyz="0 1 0" />
    <limit effort="100" velocity="50" lower="-1" upper="1" />
</joint>


<!--////////////////////////////////////////Gazebo-Eigenschaften///////////////////////////////////////////-->
 <gazebo reference="belt">
    <material>Gazebo/DarkGrey</material>
</gazebo>
<gazebo reference="cube">
    <material>Gazebo/Grey</material>
</gazebo>

<ros2_control name="GazeboSystem" type="system">
    <hardware>
        <plugin>gazebo_ros2_control/GazeboSystem</plugin>
    </hardware>
    <joint name="BeltPrismatic">
        <command_interface name="position">
            <param name="min">-1.0</param>
            <param name="max">1.0</param>
        </command_interface>
        <state_interface name="position"/>
        <state_interface name="velocity"/>
    </joint>
</ros2_control>

and the following controller:

    belt_controller:
  ros__parameters:
    joints:
      - BeltPrismatic
    command_interfaces:
      - position
      - velocity
    state_interfaces:
      - position
      - velocity
    state_publish_rate: 100.0
    action_monitor_rate: 20.0
    allow_partial_joints_goal: false
    constraints:
      stopped_velocity_tolerance: 0.01
      goal_time: 0.0
      BeltPrismatic: { trajectory: 0.01, goal: 0.1 }

and i try to get the joint to move with this code:

    import rclpy
from rclpy.node import Node
from std_msgs.msg import Float64
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint


class BeltSpeedController(Node):
    def __init__(self):
        super().__init__('BeltSpeedController')
        self.publischer = self.create_publisher(JointTrajectory, '/belt_controller/joint_trajectory', 10)
        self.subscription = self.create_subscription(Float64, 'given_belt_velocity', self.velocity_callback, 10)
        self.get_logger().info('BSC gestartet...')




    def velocity_callback(self, msg):
        velocity = msg.data
        self.get_logger().info('Geschwindigkeit erhalten: {}'.format(msg.data))

        self.trajMsg = JointTrajectory()
        self.trajMsg.joint_names = ['BeltPrismatic']
        point = JointTrajectoryPoint()
        point.positions = [1.0]  # Die gewünschte Position hier ende des förderbandes
        point.velocities = [velocity]  # Sie können dies je nach Anforderung anpassen
        self.trajMsg.points = [point]
        self.publischer.publish(self.trajMsg)
        self.get_logger().info('Geschwindigkeit und Punkt umgesetzt: {}, {}'.format(velocity, point))


def main(args=None):
    rclpy.init(args=args)
    node = BeltSpeedController()
    rclpy.spin(node)
    node.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()

Unfortunately the Cube wont move along the joint and just rest at its position, how can i get it to move. Note: The Controller and all Nodes are starting without any errors

$\endgroup$

1 Answer 1

0
$\begingroup$

Prismatic joints work for sure, see the gazebo_ros2_control_demo package.

Your yaml file is missing the controller manager part. See this example how to setup Gazebo classic simulation.

If you just missed to copy the whole file, please also add your launch file and possibly the output from ros2 control list_controllers

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.