Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class Config:
network_interface_name: Optional[str]

def __init__(self, **data: Any) -> None:
"""
Initialize a FreeAvoid instance with communication channel and client.

This method initializes the base class with any provided keyword arguments,
sets up the communication channel via ChannelFactoryInitialize using the instance's
network interface, and configures a SportClient with a 10-second timeout before
finalizing its initialization.

Args:
**data: Additional keyword arguments for tool configuration.
"""
super().__init__(**data)
ChannelFactoryInitialize(0, self.network_interface_name)
self.sport_client = SportClient()
Expand All @@ -50,6 +61,12 @@ def __init__(self, **data: Any) -> None:
@field_validator("network_interface_name")
@classmethod
def network_interface_name_validator(cls, network_interface_name: Union[str, None]) -> Union[str, None]:
"""
Validates that a network interface name is provided.

Checks that the given network interface name is not None. Raises a ValueError if no name is provided,
otherwise returns the network interface name.
"""
if network_interface_name == None:
raise ValueError("network interface name is not provided.")
return network_interface_name
Expand All @@ -59,7 +76,15 @@ def _run(
switch: bool = True
) -> Dict[str, Any]:
"""
Control the Unitree Go2 robot to free avoid.
Executes the free avoid command on the Unitree Go2 robot.

This method sends a command to control the robot's free avoid behavior using the sport_client. The provided switch flag determines whether to enable (True) or disable (False) free avoid. On success, it returns a dictionary with a success code and message; if an exception occurs, it logs the error and returns a failure dictionary.

Args:
switch (bool): True to enable free avoid, False to disable it.

Returns:
dict: A dictionary containing a status code and message indicating the outcome.
"""

try:
Expand Down
34 changes: 33 additions & 1 deletion omagent-core/src/omagent_core/tool_system/tools/ut_dog/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class Config:
network_interface_name: Optional[str]

def __init__(self, **data: Any) -> None:
"""
Initializes the Move instance and configures its SportClient.

Passes keyword arguments to the base class, initializes the communication channel
using the specified network interface, and sets up a SportClient with a 10-second
timeout before establishing its connection.
"""
super().__init__(**data)
ChannelFactoryInitialize(0, self.network_interface_name)
self.sport_client = SportClient()
Expand All @@ -60,6 +67,17 @@ def __init__(self, **data: Any) -> None:
@field_validator("network_interface_name")
@classmethod
def network_interface_name_validator(cls, network_interface_name: Union[str, None]) -> Union[str, None]:
"""
Validate that a network interface name is provided.

Ensures that a network interface name is supplied. Raises a ValueError if the value is None.

Raises:
ValueError: If network_interface_name is None.

Returns:
The provided network interface name.
"""
if network_interface_name == None:
raise ValueError("network interface name is not provided.")
return network_interface_name
Expand All @@ -71,7 +89,21 @@ def _run(
vyaw: float = 0
) -> Dict[str, Any]:
"""
Control the Go2 to move.
Sends a movement command to the Unitree Go2 robot.

This method uses the sport client to move the robot with the specified
velocities along the x and y axes and a specified yaw rotation. If the
movement command executes successfully, it returns a success response;
otherwise, it logs the error and returns a failure response.

Parameters:
vx (float): Movement along the x-axis. Defaults to 0.
vy (float): Movement along the y-axis. Defaults to 0.
vyaw (float): Rotation around the z-axis. Defaults to 0.

Returns:
dict: A response dictionary with keys 'code' and 'msg', where 'code' is 0 for
success and 500 for failure.
"""

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Config:
network_interface_name: Optional[str]

def __init__(self, **data: Any) -> None:
"""
Initializes the StandDown tool and configures its SportClient.

Sets up the base tool using provided keyword arguments, initializes the network
channel with the specified interface, and prepares a SportClient with a 10-second
timeout for communication.

Args:
**data: Arbitrary keyword arguments for tool configuration.
"""
super().__init__(**data)
ChannelFactoryInitialize(0, self.network_interface_name)
self.sport_client = SportClient()
Expand All @@ -45,6 +55,15 @@ def __init__(self, **data: Any) -> None:
@field_validator("network_interface_name")
@classmethod
def network_interface_name_validator(cls, network_interface_name: Union[str, None]) -> Union[str, None]:
"""
Ensures a network interface name is provided.

Raises:
ValueError: If no network interface name is provided.

Returns:
str: The provided network interface name.
"""
if network_interface_name == None:
raise ValueError("network interface name is not provided.")
return network_interface_name
Expand All @@ -53,7 +72,11 @@ def _run(
self
) -> Dict[str, Any]:
"""
Control the Go2 to stand down.
Attempts to command the Unitree Go2 robot to stand down.

Returns:
Dict[str, Any]: A dictionary with the operation's status where "code" is 0 for success
and 500 for failure, and "msg" indicates "success" or "failed" accordingly.
"""

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Config:
network_interface_name: Optional[str]

def __init__(self, **data: Any) -> None:
"""
Initialize the StandUp tool.

Initializes the base tool with the provided data, configures the channel factory
with the designated network interface, and sets up a sport client with a timeout
of 10 seconds for robot communication.
"""
super().__init__(**data)
ChannelFactoryInitialize(0, self.network_interface_name)
self.sport_client = SportClient()
Expand All @@ -45,6 +52,15 @@ def __init__(self, **data: Any) -> None:
@field_validator("network_interface_name")
@classmethod
def network_interface_name_validator(cls, network_interface_name: Union[str, None]) -> Union[str, None]:
"""
Validate that a network interface name is provided.

Raises:
ValueError: If network_interface_name is None.

Returns:
str: The validated network interface name.
"""
if network_interface_name == None:
raise ValueError("network interface name is not provided.")
return network_interface_name
Expand All @@ -53,7 +69,12 @@ def _run(
self
) -> Dict[str, Any]:
"""
Control the Go2 to stand up.
Commands the Unitree Go2 robot to stand up.

Sends the stand-up command through the sport_client and returns a dictionary indicating
the result. On success, it returns a dictionary with a code of 0 and a message "success".
If an error occurs, the error is logged and the method returns a dictionary with a code
of 500 and a message "failed".
"""

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class Config:
network_interface_name: Optional[str]

def __init__(self, **data: Any) -> None:
"""
Initializes the StopMove tool instance.

Calls the parent initializer with provided data, configures the network channel using the
specified network interface, and sets up the SportClient with a 10-second timeout.
"""
super().__init__(**data)
ChannelFactoryInitialize(0, self.network_interface_name)
self.sport_client = SportClient()
Expand All @@ -45,6 +51,15 @@ def __init__(self, **data: Any) -> None:
@field_validator("network_interface_name")
@classmethod
def network_interface_name_validator(cls, network_interface_name: Union[str, None]) -> Union[str, None]:
"""
Validate that a network interface name is provided.

Raises:
ValueError: If the network interface name is None.

Returns:
str: The validated network interface name.
"""
if network_interface_name == None:
raise ValueError("network interface name is not provided.")
return network_interface_name
Expand All @@ -53,7 +68,11 @@ def _run(
self,
) -> Dict[str, Any]:
"""
Control the Go2 to stop move.
Stops the robot's movement.

Attempts to issue a stop command via the sport client. If successful, returns a
dictionary with a status code of 0 and a "success" message. If an error occurs,
logs the error and returns a dictionary with a status code of 500 and a "failed" message.
"""

try:
Expand Down