Skip to content

GDK PNC Interface Documentation (Python)

Overview

The PNC (Planning and Control) module provides the G02 robot with path planning and navigation control functionality. Through the Python interface, developers can conveniently implement the robot's autonomous navigation, path planning, task state management, and other functionality, suitable for autonomous navigation, path planning, task scheduling, and many other scenarios.

Interface Description

Pnc Class

This class encapsulates the main interfaces for robot path planning and navigation control.

1. get_task_state()

  • Function: Get the current task state
  • Parameters: None
  • Return value: A PNCTaskState object, containing the following attributes:
Attribute Type Description Unit
state int Task state code integer
message str Status description string
id int Task ID integer
type int Task type integer

Task state code description: - 0: Idle - 1: Starting - 2: Running - 3: Pausing - 4: Paused - 5: Resuming - 6: Cancelling - 7: Cancelled - 8: Failed - 9: Succeeded

Task type description: - 0: Idle - 1: Normal navigation - 2: Remote control

  • Example:
import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# Get the task state
task_state = pnc.get_task_state()
print(f"PNC task state: {task_state.state}")
print(f"PNC task ID: {task_state.id}")
print(f"PNC task message: {task_state.message}")
print(f"PNC task type: {task_state.type}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

2. normal_navi()

  • Function: Execute normal navigation to a specified target point; relocalization must be performed on the G02 Pad before execution
  • Parameters: A NaviReq object (in the map coordinate frame), containing the following attributes:
Attribute Type Description Unit
target.position.x float Target position X coordinate meters
target.position.y float Target position Y coordinate meters
target.position.z float Target position Z coordinate meters
target.orientation.x float Target orientation quaternion X component unitless
target.orientation.y float Target orientation quaternion Y component unitless
target.orientation.z float Target orientation quaternion Z component unitless
target.orientation.w float Target orientation quaternion W component unitless
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# Create a navigation target
target = agibot_gdk.NaviReq()
target.target.position.x = -0.14157561800950003
target.target.position.y = 0.015152394013126735
target.target.position.z = 0.0040338473100211417
target.target.orientation.x = 0.01146358383671978
target.target.orientation.y = -0.01720065085681078
target.target.orientation.z = 0.83847410642918951
target.target.orientation.w = 0.54454926012574167

# Execute navigation
try:
    pnc.normal_navi(target)
    print("Normal navigation request sent successfully")
except Exception as e:
    print(f"Normal navigation failed: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

3. high_precision_navi() (this interface is not yet available)

  • Function: Execute high-precision navigation to a specified target point; relocalization must be performed on the G02 Pad before execution
  • Parameters: A NaviReq object (in the map coordinate frame)
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# Create a high-precision navigation target
target = agibot_gdk.NaviReq()
target.target.position.x = 1.0
target.target.position.y = 2.0
target.target.position.z = 0.0
target.target.orientation.x = 0.0
target.target.orientation.y = 0.0
target.target.orientation.z = 0.0
target.target.orientation.w = 1.0

# Execute high-precision navigation
try:
    pnc.high_precision_navi(target)
    print("High-precision navigation request sent successfully")
except Exception as e:
    print(f"High-precision navigation failed: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

4. relative_move()

  • Function: Execute a small-range translation; simple stop-on-obstacle, no obstacle avoidance; relocalization must be performed on the G02 Pad before execution
  • Parameters: A NaviReq object (in the base_link coordinate frame)
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# Create a relative move target
target = agibot_gdk.NaviReq()
target.target.position.x = 0.5  # Move forward 0.5 meters relative to current position
target.target.position.y = 0.0
target.target.position.z = 0.0
target.target.orientation.x = 0.0
target.target.orientation.y = 0.0
target.target.orientation.z = 0.0
target.target.orientation.w = 1.0

# Execute relative move
try:
    pnc.relative_move(target)
    print("Relative move request sent successfully")
except Exception as e:
    print(f"Relative move failed: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

5. cancel_task()

  • Function: Cancel the navigation task with the specified ID
  • Parameters:
Parameter Type Description
task_id int ID of the task to cancel
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# First get the current task state to obtain the task ID
try:
    task_state = pnc.get_task_state()
    task_id = task_state.id

    # Cancel the navigation task with the specified ID
    pnc.cancel_task(task_id)
    print("Cancel task request sent successfully")
except Exception as e:
    print(f"Failed to cancel task: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

6. pause_task()

  • Function: Pause the navigation task with the specified ID
  • Parameters:
Parameter Type Description
task_id int ID of the task to pause
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# First get the current task state to obtain the task ID
try:
    task_state = pnc.get_task_state()
    task_id = task_state.id

    # Pause the task with the specified ID
    pnc.pause_task(task_id)
    print("Pause task request sent successfully")
except Exception as e:
    print(f"Failed to pause task: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

7. resume_task()

  • Function: Resume the navigation task with the specified ID
  • Parameters:
Parameter Type Description
task_id int ID of the task to resume
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# First get the current task state to obtain the task ID
try:
    task_state = pnc.get_task_state()
    task_id = task_state.id

    # Resume the task with the specified ID
    pnc.resume_task(task_id)
    print("Resume task request sent successfully")
except Exception as e:
    print(f"Failed to resume task: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

8. request_chassis_control()

  • Function: Request chassis control permission, used for remote control mode
  • Parameters:
Parameter Type Description
control_mode int Control mode: 0 = Ackermann mode, 1 = crab mode
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# Request chassis control permission
try:
    pnc.request_chassis_control(0)
    print("Chassis control permission request sent successfully")
except Exception as e:
    print(f"Chassis control permission request failed: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

9. move_chassis()

  • Function: Move the chassis, used for chassis motion control in remote control mode
  • Parameters:
Parameter Type Description
twist Twist Velocity command object, containing linear velocity and angular velocity
  • Return value: None; throws an exception on failure

  • Example:

import agibot_gdk
import time

# Initialize the GDK system
if agibot_gdk.gdk_init() != agibot_gdk.GDKRes.kSuccess:
    print("GDK initialization failed")
    exit(1)
print("GDK initialized successfully")

pnc = agibot_gdk.Pnc()
time.sleep(2)  # Wait for PNC to initialize

# Request chassis control permission
try:
    pnc.request_chassis_control(0)
    print("Chassis control permission request sent successfully")
except Exception as e:
    print(f"Chassis control permission request failed: {e}")

# Create a velocity command (Ackermann movement)
twist = agibot_gdk.Twist()
twist.linear.x = 0.5  # Linear velocity 0.5 m/s
twist.angular.z = 0.1  # Angular velocity 0.1 rad/s

# Move the chassis
try:
    pnc.move_chassis(twist)
    print("Chassis move request sent successfully")
except Exception as e:
    print(f"Chassis move failed: {e}")

task_state = pnc.get_task_state()
print(f"Task state: {task_state.state}")
task_id = task_state.id
try:
    pnc.cancel_task(task_id)
    print("Cancel task request sent successfully")
except Exception as e:
    print(f"Cancel task request failed: {e}")

# Create a velocity command (crab movement)
twist = agibot_gdk.Twist()
twist.linear.x = 0.0  # Linear velocity 0 m/s
twist.linear.y = 0.5 # Leftward translation velocity 0.5 m/s
twist.angular.z = 0.0  # Angular velocity 0 rad/s

# Move the chassis
try:
    pnc.move_chassis(twist)
    print("Chassis move request sent successfully")
except Exception as e:
    print(f"Chassis move failed: {e}")

# Get the task state
task_state = pnc.get_task_state()
print(f"Task state: {task_state.state}")
task_id = task_state.id
try:
    pnc.cancel_task(task_id)
    print("Cancel task request sent successfully")
except Exception as e:
    print(f"Cancel task request failed: {e}")

# Release GDK system resources
if agibot_gdk.gdk_release() != agibot_gdk.GDKRes.kSuccess:
    print("GDK release failed")
else:
    print("GDK released successfully")

Usage Notes

  1. GDK initialization: You must call agibot_gdk.gdk_init() to initialize the GDK system before using the PNC functionality
  2. GDK release: You must call agibot_gdk.gdk_release() to release GDK system resources before the program ends
  3. Initialization wait: After creating a Pnc object, it is recommended to wait 2 seconds to ensure system initialization completes
  4. Target setting: Make sure the target position is within the robot's reachable range
  5. Coordinate frame: Be careful to use the correct coordinate frame (usually the robot body frame)
  6. Task state: Check the task state promptly to handle possible error conditions
  7. Safety considerations: Pay attention to the safety of the surrounding environment during navigation
  8. Exception handling: All interfaces throw a std::runtime_error exception on failure and need to be handled appropriately
  9. Resource management: Make sure to call cancel_task() to stop any ongoing task before the program exits

Application Scenarios

  • Autonomous navigation: Implementing the robot's autonomous movement within an environment
  • Path planning: Planning the optimal path from a starting point to a destination
  • Task scheduling: Managing the execution of multiple navigation tasks
  • Position control: Precisely controlling the robot to reach a specified position and orientation
  • Obstacle-avoidance navigation: Implementing safe navigation in a dynamic environment
  • High-precision navigation: Application scenarios requiring precise localization
  • Relative movement: Relative displacement control based on the current position
  • Task control: Dynamically pausing, resuming, or cancelling navigation tasks