Skip to content

Commit

Permalink
change robot_py to rae_sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Serafadam committed Jan 9, 2024
1 parent fea2938 commit 4951d1c
Show file tree
Hide file tree
Showing 79 changed files with 94 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
linter: ${{ matrix.linter }}
package-name: |
rae_hw
robot_py
rae_sdk
rae_description
rae_bringup
docker-build:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions robot_py/package.xml → rae_sdk/package.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>robot_py</name>
<name>rae_sdk</name>
<version>0.0.0</version>
<description>Robot Python API library</description>
<description>RAE SDK</description>
<maintainer email="[email protected]">Adam Serafin</maintainer>
<license>MIT</license>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ROSInterface:
"""

def __init__(self, name: str, namespace='', launch_mock=False) -> None:
def __init__(self, name: str, namespace='', launch_mock=False, start_hardware=True) -> None:
"""
Initialize the ROS2Manager instance.
Expand All @@ -94,6 +94,7 @@ def __init__(self, name: str, namespace='', launch_mock=False) -> None:
self._namespace = namespace
self._name = name
self._launch_mock = launch_mock
self._start_hardware = start_hardware
self._launch_service = None
self._stop_event = None
self._process = None
Expand Down Expand Up @@ -136,7 +137,7 @@ def _run_process(self, stop_event, launch_description):
asyncio.ensure_future(launch_service.shutdown(), loop=loop)
loop.run_until_complete(launch_task)

def start(self, start_hardware) -> None:
def start(self) -> None:
"""
Run RAE hardware drivers process.Initializes and starts the ROS2 node and executor. It sets up the ROS2 context and starts the ROS2 spin.
Expand All @@ -145,7 +146,7 @@ def start(self, start_hardware) -> None:
start_hardware (bool): Whether to start the hardware process or not.
"""
if start_hardware:
if self._start_hardware:
self.start_hardware_process()
self._context = rclpy.Context()
self._context.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class AudioController:
play_random_sfx(): Plays a random sound effect.
"""

def __init__(self, ros_interface):
self._ros_interface = ros_interface
self._ros_interface.create_service_client(
'/play_audio', PlayAudio)
self._assets_path = os.path.join(
get_package_share_directory('robot_py'), 'assets')
get_package_share_directory('rae_sdk'), 'assets')
log.info("Audio Controller ready")

def create_and_send_request(self, audio_file_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, ros_interface):
self._screen_width = 160
self._screen_height = 80
self._assets_path = os.path.join(
get_package_share_directory('robot_py'), 'assets')
get_package_share_directory('rae_sdk'), 'assets')
log.info("Display Controller ready")

def stop(self):
Expand Down Expand Up @@ -175,4 +175,4 @@ def ball_callback(self):
if self.y <= self.ball_size // 2 or self.y >= self.screen_height - self.ball_size // 2:
self.vy = -self.vy
bgra_image = cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)
self.display_image(bgra_image)
self.display_image(bgra_image)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, namespace=''):
self._executor_type = "single_threaded"
self._queues = {}
self._config_path = os.path.join(
get_package_share_directory('robot_py'), 'config', 'example_config.yaml')
get_package_share_directory('rae_sdk'), 'config', 'example_config.yaml')
if self.connect_to_device():
log.info(
"Perception module initialized. Now please set up the pipeline.")
Expand Down Expand Up @@ -308,7 +308,7 @@ def setup_sai_slam(self):
self.add_queue("trackedFeaturesRight", self.publish_ros)

config_path = os.path.join(get_package_share_directory(
'robot_py'), 'config', 'example_config.yaml')
'rae_sdk'), 'config', 'example_config.yaml')
self.opts = dai_ros.ROSNodeOptions("spetacularAI", self._namespace, config_path,
{'input/imu': 'imu/data',
'/input/cam0/image_rect': 'right/image_rect',
Expand Down Expand Up @@ -357,4 +357,5 @@ def setup_rtabmap(self):
"rgb/image": "right/image_rect",
"rgb/camera_info": "right/camera_info",
"depth/image": "stereo/image_raw"})
self.add_composable_node("rtabmap_slam", "rtabmap_slam::CoreWrapper", self.opts_rtabmap)
self.add_composable_node(
"rtabmap_slam", "rtabmap_slam::CoreWrapper", self.opts_rtabmap)
90 changes: 68 additions & 22 deletions robot_py/robot_py/robot/robot.py → rae_sdk/rae_sdk/robot/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,55 @@
from sensor_msgs.msg import BatteryState
from .perception.perception_system import PerceptionSystem

log.basicConfig(level=log.INFO)

class RobotOptions:
"""
A class for storing the robot's options.
Attributes
----------
start_hardware (bool): Whether to start the robot's hardware.
launch_mock (bool): Whether to launch the robot's mock.
name (str): The robot's name.
namespace (str): The robot's namespace.
launch_controllers (bool): Whether to launch the robot's controllers.
"""

def __init__(self, name='rae_api', namespace='', launch_controllers=True, start_hardware=True, launch_mock=False):
self._start_hardware = start_hardware
self._launch_mock = launch_mock
self._name = name
self._namespace = namespace
self._launch_controllers = launch_controllers

@property
def start_hardware(self):
return self._start_hardware

@property
def launch_mock(self):
return self._launch_mock

@property
def name(self):
return self._name

@property
def namespace(self):
return self._namespace

@property
def launch_controllers(self):
return self._launch_controllers


class Robot:
"""
A class representing a robot, integrating various controllers for movement, display, and LED management and interfacing with ROS2 for communication and control.
Attributes
----------
_name (str): The name of the ROS2 node.
_namespace (str): The namespace of the ROS2 node.
ros_interface (ROSInterface): An object for managing ROS2 communications and functionalities.
battery_state (BatteryState): Stores the current state of the robot's battery.
led_controller (LEDController): Controls the robot's LEDs.
Expand All @@ -30,35 +70,35 @@ class Robot:
battery_state_cb(data): Callback method for updating battery state.
start(): Initializes the robot's components and starts ROS2 communications.
stop(): Stops the ROS2 communications and shuts down the robot's components.
"""

def __init__(self, start_hardware=True, launch_mock=False, name='rae_api', namespace=''):
def __init__(self, robot_options: RobotOptions = RobotOptions()):
"""
Initialize the Robot instance.
Args:
----
start_hardware (bool, optional): If True, starts the robot's hardware components. Defaults to True.
launch_mock (bool, optional): If True, launches mock nodes for the robot's hardware components. Defaults to False.
name (str, optional): The name of the ROS2 node. Defaults to 'rae_api'.
namespace (str, optional): The namespace of the ROS2 node. Defaults to ''.
robot_options (RobotOptions): An object containing the robot's options.
"""
self._name = name
self._namespace = namespace
self._launch_mock = launch_mock
self._ros_interface = ROSInterface(self._name, self._namespace, self._launch_mock)
self._ros_interface.start(start_hardware)
self._led_controller = LEDController(self._ros_interface)
self._display_controller = DisplayController(self._ros_interface)
self._movement_controller = MovementController(self._ros_interface)
self._audio_controller = AudioController(self._ros_interface)
self._ros_interface.create_subscriber(
"/battery_status", BatteryState, self.battery_state_cb)
self._name = robot_options.name
self._namespace = robot_options.namespace
self._launch_mock = robot_options.launch_mock
self._ros_interface = ROSInterface(
self._name, self._namespace, self._launch_mock, robot_options.launch_controllers)
self._ros_interface.start()
if robot_options.launch_controllers:
self._led_controller = LEDController(self._ros_interface)
self._display_controller = DisplayController(self._ros_interface)
self._movement_controller = MovementController(self._ros_interface)
self._audio_controller = AudioController(self._ros_interface)
self._ros_interface.create_subscriber(
"/battery_status", BatteryState, self.battery_state_cb)
self._perception_system = PerceptionSystem(self._namespace)

log.info('Robot ready')

def __del__(self) -> None:
self.stop()

Expand All @@ -77,23 +117,29 @@ def battery_state_cb(self, data):
self._battery_state = data

@property
def battery_state(self)->BatteryState:
def battery_state(self) -> BatteryState:
return self._battery_state

@property
def perception_system(self) -> PerceptionSystem:
return self._perception_system

@property
def ros_interface(self) -> ROSInterface:
return self._ros_interface

@property
def led(self) -> LEDController:
return self._led_controller

@property
def display(self) -> DisplayController:
return self._display_controller

@property
def movement(self) -> MovementController:
return self._movement_controller

@property
def audio(self) -> AudioController:
return self._audio_controller
return self._audio_controller
File renamed without changes.
Empty file added rae_sdk/resource/rae_sdk
Empty file.
File renamed without changes.
4 changes: 4 additions & 0 deletions rae_sdk/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/rae_sdk
[install]
install_scripts=$base/lib/rae_sdk
14 changes: 7 additions & 7 deletions robot_py/setup.py → rae_sdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from glob import glob
from setuptools import find_packages, setup

package_name = 'robot_py'
submodules=['robot_py/robot', 'robot_py/api']
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
]
package_name = 'rae_sdk'
submodules = ['rae_sdk/robot', 'rae_sdk/api']
data_files = [
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
]


def package_files(data_files, directory_list):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions robot_py/setup.cfg

This file was deleted.

0 comments on commit 4951d1c

Please sign in to comment.