Challenge - 5 Problems
Gripper Control Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output of this ROS node controlling a gripper?
Consider a ROS node that publishes a command to open a gripper. What will the gripper's state be after this node runs once?
ROS
import rclpy from rclpy.node import Node from std_msgs.msg import String class GripperController(Node): def __init__(self): super().__init__('gripper_controller') self.publisher_ = self.create_publisher(String, 'gripper_command', 10) msg = String() msg.data = 'open' self.publisher_.publish(msg) self.get_logger().info('Sent open command') def main(args=None): rclpy.init(args=args) node = GripperController() rclpy.spin_once(node) node.destroy_node() rclpy.shutdown() if __name__ == '__main__': main()
Attempts:
2 left
💡 Hint
Think about what happens when a message is published once on a topic the gripper listens to.
✗ Incorrect
Publishing the 'open' command once sends the instruction to the gripper. The gripper will act on this command and open. It does not require continuous publishing to change state.
❓ state_output
intermediateWhat is the gripper state after this ROS subscriber callback?
Given a ROS subscriber node that listens to 'gripper_status' topic and updates an internal state variable, what will be the value of 'self.is_open' after receiving the message 'closed'?
ROS
import rclpy from rclpy.node import Node from std_msgs.msg import String class GripperStatusListener(Node): def __init__(self): super().__init__('gripper_status_listener') self.is_open = None self.subscription = self.create_subscription( String, 'gripper_status', self.listener_callback, 10) def listener_callback(self, msg): if msg.data == 'open': self.is_open = True elif msg.data == 'closed': self.is_open = False # Assume a message with data 'closed' is received
Attempts:
2 left
💡 Hint
Check the condition that sets self.is_open when the message data is 'closed'.
✗ Incorrect
The callback sets self.is_open to False when the message data is 'closed'. So after receiving 'closed', self.is_open is False.
📝 Syntax
advancedWhich option correctly initializes a ROS2 action client for gripper control?
You want to create an action client in ROS2 to send a goal to a gripper action server. Which code snippet correctly initializes the action client?
Attempts:
2 left
💡 Hint
Check the ROS2 ActionClient constructor signature: it requires the node, action type, then action name.
✗ Incorrect
The correct constructor for ActionClient is ActionClient(node, action_type, action_name). Option B follows this order correctly.
🔧 Debug
advancedWhy does this ROS2 gripper control node fail to send commands?
This ROS2 node tries to publish gripper commands but the gripper never moves. What is the likely cause?
ROS
import rclpy from rclpy.node import Node from std_msgs.msg import String class GripperController(Node): def __init__(self): super().__init__('gripper_controller') self.publisher_ = self.create_publisher(String, 'gripper_command', 10) def send_command(self, command): msg = String() msg.data = command self.publisher_.publish(msg) def run(self): self.send_command('open') def main(args=None): rclpy.init(args=args) node = GripperController() rclpy.spin(node) node.run() node.destroy_node() rclpy.shutdown()
Attempts:
2 left
💡 Hint
Consider when the message is published relative to the ROS spinning.
✗ Incorrect
Publishing before spinning means no ROS communication is fully set up, so the message may not be sent. Publishing after spinning or using timers ensures delivery.
🧠 Conceptual
expertWhat is the main advantage of using ROS2 actions for gripper control over simple topic publishing?
ROS2 offers topics, services, and actions for communication. Why is using an action interface better for controlling a gripper that needs to open or close with feedback?
Attempts:
2 left
💡 Hint
Think about what features actions provide beyond simple message sending.
✗ Incorrect
Actions support goal sending with feedback and result messages, which is useful for controlling devices like grippers that take time to complete movements.
