Skip to content

teleop_node.md

dingdongdengdong edited this page May 5, 2025 · 2 revisions

Teleoperation Node (teleop_node.py)

flow chart

graph TD
    A[Start] --> B{Initialize ROS 2};
    B --> C[Create teleop_node];
    C --> D[Create cam_pose Publisher];
    C --> E[Create goal_pose Publisher];
    E --> F[Define pub_T Helper Function];
    F --> G[Initialize Tcamgoal_last to None];
    G --> H[Define cb Callback Function];
    H --> I[Get Camera Processing Object];
    I --> J[while True Loop Starts];
    J --> K[Process Camera Data get tag2cam];
    K --> L[pprint tag2cam_left];
    K --> M[pprint tag2cam_right];
    M --> N[Call cb with tag2cam_right];

    N --> O[cb Function Executes];
    O --> P[Define Tscam base_link to camera];
    P --> Q[Call pub_T with pub_cam and Tscam];
    Q --> R{Tcamgoal_last is None?};
    R -- Yes --> S[Initialize Tcamgoal_last with Tcamgoal];
    S --> T[Set Low Pass Coefficient];
    T --> U[Apply Slerp Smoothing to Tcamgoal];
    U --> V[Update Tcamgoal_last with Smoothed Tcamgoal];
    V --> W[Compute Tsgoal = Tscam @ Smoothed Tcamgoal];
    W --> X[Call pub_T with pub and Tsgoal];
    X --> J;
    R -- No --> T;

    J --> Y[rclpy.spin node];
    Y --> Z[Unreachable Code];

    Q --> Y;
    X --> Y;
Loading

Class Structure

classDiagram
    class TeleopNode {
        -Node node
        -camera_publisher
        -goal_pose_publisher
        -transform_listener
        -buffer
        -last_pose
        -filter_alpha
        +__init__()
        -process_camera_data()
        -transform_poses()
        -apply_low_pass_filter()
        -publish_goal_pose()
    }

    class TransformListener {
        +lookup_transform()
        +wait_for_transform()
    }

    class PoseProcessor {
        +process_raw_pose()
        +filter_pose()
        +validate_pose()
    }

    TeleopNode --> TransformListener : uses
    TeleopNode --> PoseProcessor : uses
Loading

Component Interaction

flowchart TD
    subgraph TeleopNode
        CD[Camera Data Handler]
        PP[Pose Processor]
        TF[Transform Handler]
        LP[Low-Pass Filter]
        PB[Pose Publisher]
    end

    subgraph External
        CAM[Camera Input]
        TFT[TF Tree]
        GP[Goal Pose Topic]
    end

    CAM -->|raw data| CD
    CD -->|processed data| PP
    PP -->|raw pose| LP
    LP -->|filtered pose| TF
    TFT -->|transforms| TF
    TF -->|transformed pose| PB
    PB -->|goal pose| GP

    style TeleopNode fill:#bbf,stroke:#333,stroke-width:2px
    style External fill:#fbb,stroke:#333,stroke-width:2px
Loading

Data Flow

sequenceDiagram
    participant Camera
    participant DataProcessor
    participant Filter
    participant Transform
    participant Publisher

    loop Processing Loop
        Camera->>DataProcessor: Raw Camera Data
        DataProcessor->>Filter: Processed Pose
        Filter->>Transform: Filtered Pose
        Transform->>Transform: Apply Transforms
        Transform->>Publisher: Transformed Pose
        Publisher->>External: Goal Pose
    end
Loading

Transform Pipeline

graph LR
    subgraph Input
        A[Camera Frame]
    end

    subgraph Transforms
        B[Camera to Base]
        C[Base to World]
    end

    subgraph Output
        D[World Frame]
    end

    A -->|transform| B
    B -->|transform| C
    C -->|result| D

    style Input fill:#bbf
    style Transforms fill:#fbf
    style Output fill:#fbb
Loading

State Machine

stateDiagram-v2
    [*] --> Initializing
    Initializing --> WaitingForCamera: Node Ready
    WaitingForCamera --> Processing: Camera Connected
    Processing --> TransformingPose: Data Received
    TransformingPose --> Publishing: Transform Success
    Publishing --> Processing: Publish Complete
    Processing --> WaitingForCamera: Camera Error
    Processing --> [*]: Shutdown
Loading

Error Handling

flowchart TD
    A[Error Detected] --> B{Error Type}
    B -->|Camera| C[Retry Connection]
    B -->|Transform| D[Wait for Transform]
    B -->|Processing| E[Skip Frame]
    C --> F{Success?}
    D --> F
    E --> F
    F -->|Yes| G[Resume Operation]
    F -->|No| H[Log Error]
    H --> I[Continue]
Loading

Configuration Parameters

  • filter_alpha: Low-pass filter coefficient (0-1)
  • camera_topic: Input camera topic name
  • goal_pose_topic: Output pose topic name
  • transform_timeout: TF lookup timeout (seconds)
  • processing_rate: Main loop rate (Hz)

Topics and Frames

Subscribed Topics

  • Camera input topic (sensor_msgs/Image)
  • TF topics (tf2_msgs/TFMessage)

Published Topics

  • Goal pose (geometry_msgs/PoseStamped)
  • Processed camera data (sensor_msgs/Image)

Transform Frames

  • camera_link
  • base_link
  • world

Dependencies

  • ROS2 Packages:
    • rclpy
    • sensor_msgs
    • geometry_msgs
    • tf2_ros
    • cv_bridge
  • Python Libraries:
    • numpy
    • opencv-python
    • pytransform3d

Notes

  • Implements smooth pose filtering
  • Handles coordinate frame transformations
  • Provides real-time visual feedback
  • Supports multiple camera types
  • Error-resistant processing pipeline
  • Configurable processing parameters
  • Thread-safe operation

Clone this wiki locally