Skip to content

Conversation

@Fouad-Smaoui
Copy link

Implement advanced navigation and docking sensor improvements

Overview

This PR enhances the Create3 robot's capabilities by implementing sophisticated navigation features and addressing pending TODO items. The changes focus on improving autonomous movement, obstacle avoidance, and docking sensor functionality.

Major Changes

1. TODO Items Implementation

  • Docking Sensor Enum

    • Added DockSensorEnum for structured sensor state management
    • Defined clear states for contact and IR sensors
    • Improved type safety and code clarity
  • Event Trigger System

    • Replaced generic event firing with specific triggers
    • Implemented trigger-based event system for docking sensors
    • Added when_docking_sensor_trigger for granular event handling
  • Docking Values Optimization

    • Implemented cached value access in get_docking_values
    • Reduced unnecessary robot queries
    • Added proper error handling and fallback mechanisms

2. Advanced Navigation Features

  • Waypoint Navigation

    • Added Waypoint dataclass for structured navigation points
    • Implemented navigate_to_waypoint for precise navigation
    • Added follow_waypoints for sequential navigation
  • Obstacle Avoidance

    • Real-time obstacle detection using IR sensors
    • Smart avoidance algorithm with configurable parameters
    • Added navigate_with_obstacle_avoidance for safe navigation
  • Navigation State Management

    • Added NavigationState for comprehensive state tracking
    • Implemented methods for state monitoring and control
    • Added emergency stop functionality

Technical Details

Configuration Parameters

OBSTACLE_DETECTION_THRESHOLD = 30  # cm
OBSTACLE_AVOIDANCE_DISTANCE = 50   # cm
NAVIGATION_SPEED = 0.5             # m/s

Usage Examples

Docking Sensor Usage

# Register for any docking sensor event
robot.when_docking_sensor(lambda state: print(f"Docking sensor state changed: {state}"))

# Register for specific triggers
robot.when_docking_sensor_trigger(
    Create3.DockSensorEnum.CONTACT,
    lambda state: print("Contact detected!")
)

Navigation Usage

# Create and follow waypoints
waypoint1 = Waypoint(x=100, y=100, heading=90)
waypoint2 = Waypoint(x=200, y=100, heading=180)
success = await robot.follow_waypoints([waypoint1, waypoint2])

# Navigate with obstacle avoidance
success = await robot.navigate_with_obstacle_avoidance(x=150, y=150, heading=45)

# Monitor navigation state
state = robot.get_navigation_state()
if state.is_navigating:
    print(f"Currently navigating to: {state.current_waypoint}")

Safety Features

  • Pre-navigation obstacle checks
  • Waypoint verification with configurable tolerances
  • Graceful handling of navigation failures
  • Emergency stop capability
  • Proper error handling throughout

@raphaelcherney raphaelcherney requested a review from shamlian May 19, 2025 20:28
@shamlian shamlian changed the base branch from main to pre_0.7.0 June 9, 2025 22:54
Copy link
Collaborator

@shamlian shamlian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I am no longer an employee of iRobot Corporation but it seems I'm implicitly the steward of this repository.

This is impressive work. Would you mind adding an example (you could just crib them from the text of this PR, if you want) to examples/create3_robots ? Once you do that I'd be happy to merge to pre_0.7.0.

# Update cached values
self.docking_sensor.contacts = packet.payload[4] != 0
self.docking_sensor.sensors = (packet.payload[5],
packet.payload[6],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you restore the indentation on this tuple, please?

packet = await completer.wait(self.DEFAULT_TIMEOUT)
if packet:
unpacked = unpack('>IBBBBHHHH', packet.payload)
return {'timestamp': unpacked[0], 'contacts': unpacked[1], 'IR sensor 0': unpacked[2],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is much more readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants