This tutorial covers the complete pick and place workflow, from scanning for objects to executing precise placement in designated zones. You’ll learn how to coordinate motion planning, serial communication, and error handling.
Pick and place operations require prior scanning to identify object positions. Always run a scan first.
from arm_system.main import Robotrobot = Robot()robot.run()# In the menu, press 'n' to scan# Or programmatically:robot.handle_scan_command()
This populates robot.scan_results with detected objects.
2
Verify Scan Results
Check that objects were detected:
if not robot.scan_results: print("No objects detected. Run scan first.") returnprint(f"Found {len(robot.scan_results)} objects")for obj in robot.scan_results: print(f"Object {obj['index']}: {obj['class']} at {obj['center_angle']}°")
The robot presents detected objects for selection:
# From main.py:151-169def select_object_interactively(self): """Interface for object selection""" print("\n=== OBJECTS DETECTED LIST ===") for o in self.scan_results: i = o['index'] print(f"[{i}] angle={o['center_angle']}° dist={o['distance']}mm class={o['class']} conf={o['confidence']:.2f}") print("[0] cancelar") try: selection = int(input("\nselect the object you want to take: ")) if selection == 0: print("operation canceled") return {} return next((x for x in self.scan_results if x['index'] == selection), {}) except ValueError: print("invalid input") return {}
Example interaction:
=== OBJECTS DETECTED LIST ===[1] angle=45° dist=150mm class=apple conf=0.89[2] angle=120° dist=180mm class=orange conf=0.92[3] angle=200° dist=160mm class=bottle conf=0.87[0] cancelarselect the object you want to take: 1
2
Programmatic Selection
Select objects programmatically:
# Select by indexselected = robot.scan_results[0]# Select highest confidenceselected = max(robot.scan_results, key=lambda x: x['confidence'])# Select by classselected = next((x for x in robot.scan_results if x['class'] == 'apple'), None)# Select closestselected = min(robot.scan_results, key=lambda x: x['distance'])
# From main.py:132-149def handle_pick_place_command(self): """Pick & place command""" if not self.scan_results: log.warning("1. first scanning the environment (option 'n')") return selected_object = self.select_object_interactively() if not selected_object: return log.info(f"\ninit pick & place to object: {selected_object['index']}:") log.info(f"angle: {selected_object['center_angle']}°") log.info(f"distance: {selected_object['distance']} mm") if self.execute_pick_sequence(selected_object): log.info(f"¡pick completed!") if self.execute_place_sequence(selected_object): log.info(f"¡pick and place completed!")
from arm_system.main import Robotimport logging as loglog.basicConfig(level=log.INFO, format="%(asctime)s - %(levelname)s - %(message)s")def automated_pick_and_place(): """Automated pick and place demo""" robot = Robot() # Connect if not robot.serial_manager.connect(): print("Failed to connect") return print("Connected! Starting scan...") # Scan environment robot.handle_scan_command() if not robot.scan_results: print("No objects found") robot.serial_manager.close() return # Pick and place all objects for obj in robot.scan_results: print(f"\nProcessing object {obj['index']}: {obj['class']}") if robot.execute_pick_sequence(obj): print(f"✓ Picked {obj['class']}") if robot.execute_place_sequence(obj): print(f"✓ Placed {obj['class']} in zone") else: print(f"✗ Failed to place {obj['class']}") break else: print(f"✗ Failed to pick {obj['class']}") break print("\nAll operations complete!") robot.serial_manager.close()if __name__ == '__main__': automated_pick_and_place()
def place_by_confidence(robot, scan_results): """Place high confidence objects in premium zone""" for obj in scan_results: # Override placement zone based on confidence if obj['confidence'] > 0.9: obj['placement_zone'] = {'angle': 45, 'distance': 180} else: obj['placement_zone'] = {'angle': 270, 'distance': 220} # Execute pick and place if robot.execute_pick_sequence(obj): robot.execute_place_sequence(obj)