diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..02486f81 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ + +FROM ros:humble + +# Define a few key variables +ENV USERNAME=spaceros-user +ENV HOME_DIR=/home/spaceros-user +ENV DEMO_DIR=${HOME_DIR}/demo_ws +ENV ROSDISTRO=humble + + +# Disable prompting during package installation +ARG DEBIAN_FRONTEND=noninteractive + +# Get rosinstall_generator +# Using Docker BuildKit cache mounts for /var/cache/apt and /var/lib/apt ensures that +# the cache won't make it into the built image but will be maintained between steps. +RUN sudo apt update && sudo apt install -y python3-pip \ + ros-${ROSDISTRO}-control-msgs \ + ros-${ROSDISTRO}-rviz-common \ + ros-${ROSDISTRO}-rmw-cyclonedds-cpp \ + ros-${ROSDISTRO}-geometry-msgs \ + ros-${ROSDISTRO}-sensor-msgs \ + ros-${ROSDISTRO}-std-msgs \ + ros-${ROSDISTRO}-rosidl-typesupport-fastrtps-cpp \ + ros-${ROSDISTRO}-rosidl-typesupport-fastrtps-c \ + ros-${ROSDISTRO}-rviz2 \ + && sudo rm -rf /var/lib/apt/lists/* + +RUN pip install vcstool +RUN mkdir -p ${DEMO_DIR}/src +WORKDIR ${DEMO_DIR} + + +# Get the source for the dependencies +COPY --chown=${USERNAME}:${USERNAME} demo_manual_pkgs.repos /tmp/ +RUN vcs import src < /tmp/demo_manual_pkgs.repos + +#RUN sudo apt-get update -y && rosdep install --from-paths src --ignore-src -r -y --rosdistro ${ROSDISTRO} + + +# Build the demo +RUN /bin/bash -c 'source /opt/ros/${ROSDISTRO}/setup.bash \ + && colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release -Wno-dev' + +# Setup the entrypoint +COPY ./entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh"] +CMD ["bash"] diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..80d04955 --- /dev/null +++ b/build.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +ORG=openrobotics +IMAGE=space_robots_demo +TAG=latest + +VCS_REF="" +VERSION=preview + +# Exit script with failure if build fails +set -eo pipefail + +echo "" +echo "##### Building Space ROS Demo Docker Image #####" +echo "" + +docker build -t $ORG/$IMAGE:$TAG \ + --build-arg VCS_REF="$VCS_REF" \ + --build-arg VERSION="$VERSION" . + +echo "" +echo "##### Space ROS Demo Docker Image Build Completed! #####" + diff --git a/demo_manual_pkgs.repos b/demo_manual_pkgs.repos new file mode 100644 index 00000000..b4a43c1d --- /dev/null +++ b/demo_manual_pkgs.repos @@ -0,0 +1,9 @@ +repositories: + demos: + type: git + url: https://github.com/magnivia4Consulting/demos.git + version: main + simulation: + type: git + url: https://github.com/magnivia4Consulting/simulation.git + version: main diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..8b8873eb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +# Setup the Demo environment +# source "${DEMO_DIR}/install/setup.bash" +source "/home/spaceros-user/demo_ws/install/setup.bash" +exec "$@" diff --git a/mars_rover_nvidia_isaac/CMakeLists.txt b/mars_rover_nvidia_isaac/CMakeLists.txt new file mode 100644 index 00000000..686f9da1 --- /dev/null +++ b/mars_rover_nvidia_isaac/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.8) +project(mars_rover_nvidia_isaac) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(ament_cmake_python REQUIRED) +# find_package(control_msgs REQUIRED) +# find_package(geometry_msgs REQUIRED) +find_package(rclcpp REQUIRED) +# find_package(rclcpp_action REQUIRED) +find_package(rclpy REQUIRED) +# find_package(simulation REQUIRED) +find_package(std_msgs REQUIRED) +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # comment the line when a copyright and license is added to all source files + set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # comment the line when this package is in a git repo and when + # a copyright and license is added to all source files + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +install(DIRECTORY + config + launch + DESTINATION share/${PROJECT_NAME} +) + +ament_python_install_package(${PROJECT_NAME}) + +install(PROGRAMS + mars_rover_nvidia_isaac/isaac_controller_loader.py + mars_rover_nvidia_isaac/nodes/wheel_velocity_controller.py + mars_rover_nvidia_isaac/nodes/steer_position_controller.py + mars_rover_nvidia_isaac/nodes/arm_joint_trajectory_controller.py + mars_rover_nvidia_isaac/nodes/mast_joint_trajectory_controller.py + mars_rover_nvidia_isaac/nodes/wheel_tree_position_controller.py + mars_rover_nvidia_isaac/nodes/run_isaac_demo.py + DESTINATION lib/${PROJECT_NAME} +) + +ament_package() diff --git a/mars_rover_nvidia_isaac/LICENSE b/mars_rover_nvidia_isaac/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/mars_rover_nvidia_isaac/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/README.md b/mars_rover_nvidia_isaac/README.md new file mode 100644 index 00000000..d3de50ec --- /dev/null +++ b/mars_rover_nvidia_isaac/README.md @@ -0,0 +1,32 @@ +# Mars Rover Demo for Nvidia ISAAC + +This pacakge reconfigures the controllers implemented in **mars_rover** package into separate controllers and adds a controller loader to load the configuration from the **config > isaac_mars_rover_control.yaml** file in the config folder. The list of supported controllers is mentioned in the **config > isaac_controller_loader_config.yaml** file + +To run the demo with NVIDIA ISAAC, following steps need to be followed: + +1. **build.sh** script will create a docker image with name **openrobotics/space_robots_demo** + +2. To enable execution of UI applications in the container, execute the following command on the host PC: + ```bash + xhost + + ``` +3. Create a container from the docker image created in step 1, using the following command: + ```bash + docker run -it --env="DISPLAY=$DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" --env="XAUTHORITY=$XAUTH" --volume="$XAUTH:$XAUTH" --net=host openrobotics/space_robots_demo bash + ``` +4. Container will start in the directory **/home/spaceros-user/demo_ws**. + +5. Follow the setup instructions mendtioned in **src/simulation/curiosity_nvidia_isaac/README.md** to setup Nvidia ISAAC Simulation. + +6. Once NVIDIA ISAAC is up and runnnig, execute the following commands (inside the container created in step 3) to run the demo + ```bash + cd /home/spaceros-user/demo_ws + source install/setup.bash + ros2 launch mars_rover_nvidia_isaac mars_rover_nvidia_isaac_launch.py + ``` +7. Above command will load all the supported controllers and launch RViz2 with the custom teleop plugin, camera window and LIDAR data enabled. +

+ Controllers and RViz2 Plugin +

+ +8. At this point rover in Nvidia ISAAC simulation should move as per the tele-op command given and sensor data from ISAAC should be visible on RViz2 \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/config/isaac_controller_loader_config.yaml b/mars_rover_nvidia_isaac/config/isaac_controller_loader_config.yaml new file mode 100644 index 00000000..5b1c6278 --- /dev/null +++ b/mars_rover_nvidia_isaac/config/isaac_controller_loader_config.yaml @@ -0,0 +1,6 @@ +supported_controllers: + wheel_velocity_controller + steer_position_controller + arm_joint_trajectory_controller + mast_joint_trajectory_controller + wheel_tree_position_controller \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/config/isaac_mars_rover_control.yaml b/mars_rover_nvidia_isaac/config/isaac_mars_rover_control.yaml new file mode 100644 index 00000000..8d40bf73 --- /dev/null +++ b/mars_rover_nvidia_isaac/config/isaac_mars_rover_control.yaml @@ -0,0 +1,88 @@ +arm_joint_trajectory_controller: + joints: + - arm_01_joint + - arm_02_joint + - arm_03_joint + - arm_04_joint + - arm_tools_joint + # interface_name: position # NOT supported currently + # command_interfaces: + # - position + # state_interfaces: + # - position + # - velocity + +mast_joint_trajectory_controller: + joints: + - mast_p_joint + - mast_02_joint + - mast_cameras_joint + # interface_name: position # NOT supported currently + # command_interfaces: + # - position + # state_interfaces: + # - position + # - velocity + +wheel_velocity_controller: + joints: + - front_wheel_L_joint + - middle_wheel_L_joint + - back_wheel_L_joint + - front_wheel_R_joint + - middle_wheel_R_joint + - back_wheel_R_joint + # interface_name: velocity # NOT supported currently + + +steer_position_controller: + joints: + - suspension_steer_F_L_joint + - suspension_steer_B_L_joint + - suspension_steer_F_R_joint + - suspension_steer_B_R_joint + # interface_name: position # NOT supported currently + # command_interfaces: + # - position + # state_interfaces: + # - position + # - velocity + +wheel_tree_position_controller: + joints: + - suspension_arm_F_L_joint + - suspension_arm_B_L_joint + - suspension_arm_F_R_joint + - suspension_arm_B_R_joint + # command_interfaces: # NOT supported currently + # - effort + # state_interfaces: + # - position + # - velocity + # - effort + # gains: # Currently, not being applied through code, they are set directly in ISAAC + # suspension_arm_F_L_joint: + # p: 2200.0 + # i: 10.0 + # d: 10.0 + # suspension_arm_B_L_joint: + # p: 4200.0 + # i: 10.0 + # d: 10.0 + # suspension_arm_F_R_joint: + # p: 2200.0 + # i: 10.0 + # d: 10.0 + # suspension_arm_B_R_joint: + # p: 4200.0 + # i: 10.0 + # d: 10.0 + # enable: + # suspension_arm_F_L_joint: + # status: 1 + # suspension_arm_B_L_joint: + # status: 1 + # suspension_arm_F_R_joint: + # status: 1 + # suspension_arm_B_R_joint: + # status: 1 diff --git a/mars_rover_nvidia_isaac/documents/images/spaceROS_Rviz.png b/mars_rover_nvidia_isaac/documents/images/spaceROS_Rviz.png new file mode 100644 index 00000000..8ddbf1b7 Binary files /dev/null and b/mars_rover_nvidia_isaac/documents/images/spaceROS_Rviz.png differ diff --git a/mars_rover_nvidia_isaac/documents/images/spaceROS_Rviz_Sensor.png b/mars_rover_nvidia_isaac/documents/images/spaceROS_Rviz_Sensor.png new file mode 100644 index 00000000..95af0ca6 Binary files /dev/null and b/mars_rover_nvidia_isaac/documents/images/spaceROS_Rviz_Sensor.png differ diff --git a/mars_rover_nvidia_isaac/launch/mars_rover_nvidia_isaac_launch.py b/mars_rover_nvidia_isaac/launch/mars_rover_nvidia_isaac_launch.py new file mode 100644 index 00000000..cdcf73f6 --- /dev/null +++ b/mars_rover_nvidia_isaac/launch/mars_rover_nvidia_isaac_launch.py @@ -0,0 +1,72 @@ +# ROS2 +from launch import LaunchDescription +from launch_ros.actions import Node +import launch.logging + +from ament_index_python.packages import get_package_share_directory + +# Internal +from mars_rover_nvidia_isaac.isaac_controller_loader import ControllerLoader + +# System +from pathlib import Path + +def generate_launch_description(): + + logger = launch.logging.get_logger('launch_logger') + + package_share_path = get_package_share_directory("mars_rover_nvidia_isaac") + param_file_path = Path(package_share_path, 'config', 'isaac_mars_rover_control.yaml') + + controller_loader_config_file = Path(package_share_path, 'config', 'isaac_controller_loader_config.yaml') + + logger.info("Creating cocntroller loader") + controller_loader = ControllerLoader(param_file_path, controller_loader_config_file) + + # node.get_logger().info("LOADING Following controllers...") + logger.info("Getting Controllers to load") + controllers = controller_loader.get_loaded_controllers() + + nodes = [] + for name in controllers: + status, joints = controller_loader.get_joints_for_controller(name) + if status == "SUPPORTED": + if joints is None: + logger.info("No Joints provided for {}. Skipping...".format(name)) + else: + logger.info("LAUNCHING Controller:: {} for Joints:: {}".format(name, joints)) + node = Node(package='mars_rover_nvidia_isaac', + executable=name+'.py', + name=name, + arguments=[joints], + output='screen' + ) + nodes.append(node) + elif status == "UNSUPPORTED": + logger.info("UNSUPPORTED Controller:: {}. Skipping...".format(name)) + + run_node = Node( + package="mars_rover_nvidia_isaac", + executable="run_isaac_demo.py", + output='screen' + ) + + nodes.append(run_node) + + rviz_teleop_pkg_path = get_package_share_directory('mars_rover_teleop') + rviz_config_file = Path(rviz_teleop_pkg_path, 'config', 'rviz_teleop_sensors.rviz') + logger.info("RVIZ config file:: {}".format(rviz_config_file)) + + rviz_node = Node( + package='rviz2', + executable='rviz2', + name='rviz2', + output='screen', + arguments=['-d', str(rviz_config_file)] # '-d' tells RViz to use the provided config file + ) + + nodes.append(rviz_node) + + + + return LaunchDescription(nodes) \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/__init__.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/isaac_controller_loader.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/isaac_controller_loader.py new file mode 100755 index 00000000..22563c68 --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/isaac_controller_loader.py @@ -0,0 +1,48 @@ +#! /usr/bin/env python3 + +import yaml +from pathlib import Path + +class ControllerLoader(): + + def __init__(self, file, pkg_config_file): + + self.config_file_ = file + self.config_ = self._load_params_from_file() + self.pkg_config_ = self._load_package_configuration(pkg_config_file) + + self._set_supported_controllers() + + def _load_package_configuration(self, pkg_config_file): + with open(pkg_config_file, 'r') as f: + return yaml.safe_load(f) + + + def _load_params_from_file(self): + with open(self.config_file_, 'r') as f: + return yaml.safe_load(f) + + def print_params(self): + #TODO + pass + + def get_loaded_controllers(self): + return self.config_.keys() + + + def _set_supported_controllers(self): + self.supported_controllers_ = self.pkg_config_['supported_controllers'] + + + def get_joints_for_controller(self, name): + + joints = None + status = "UNSUPPORTED" + if name in self.supported_controllers_: + status = "SUPPORTED" + if 'joints' in self.config_[name].keys(): + joints_list = self.config_[name]['joints'] + + joints = ",".join(joints_list) + + return status, joints \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/__init__.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/arm_joint_trajectory_controller.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/arm_joint_trajectory_controller.py new file mode 100755 index 00000000..80ab7a56 --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/arm_joint_trajectory_controller.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 + +import rclpy +from rclpy.node import Node +from builtin_interfaces.msg import Duration + +# from std_msgs.msg import String, Float64 +from sensor_msgs.msg import JointState +from std_srvs.srv import Empty +import time + +import sys + +class ArmController(Node): + + def __init__(self, joints): + super().__init__('arm_joint_trajectory_controller') + self.get_logger().info("Initializing arm_joint_trajectory_controller node...") + + self.joints_ = joints.split(",") + + # Publisher for JointState + self.arm_publisher_ = self.create_publisher(JointState, '/arm_joint_state_controller/commands', 10) + + # Services for controlling the arm + self.open_srv = self.create_service(Empty, 'open_arm', self.open_arm_callback) + self.close_srv = self.create_service(Empty, 'close_arm', self.close_arm_callback) + + # Initialize joint states + self.current_positions = [0.0, 0.0, 0.0, 0.0, 0.0] # Default joint positions + self.get_logger().info("arm_joint_trajectory_controller node initialized and ready.") + + def open_arm_callback(self, request, response): + # Define desired positions for opening the arm + desired_positions = [0.0, -0.5, 3.0, 1.0, 0.0] + self.move_arm(desired_positions, duration=4.0) + return response + + def close_arm_callback(self, request, response): + # Define desired positions for closing the arm + desired_positions = [-1.57, -0.4, -1.1, -1.57, -1.57] + self.move_arm(desired_positions, duration=4.0) + return response + + def move_arm(self, desired_positions, duration): + # Calculate the number of steps based on the timer period (0.1s) + steps = int(duration / 0.02) + + # Calculate the incremental step size for each position + increments = [ + (desired_positions[i] - self.current_positions[i]) / steps + for i in range(len(self.current_positions)) + ] + + # Gradually update positions over the specified duration + for step in range(steps): + # Update the current positions by adding the increments + self.current_positions = [ + self.current_positions[i] + increments[i] + for i in range(len(self.current_positions)) + ] + + # Create JointState message + joint_state_msg = JointState() + # joint_state_msg.name = ["arm_01_joint", "arm_02_joint", "arm_03_joint", "arm_04_joint", "arm_tools_joint"] + joint_state_msg.name = self.joints_ + joint_state_msg.position = self.current_positions + + # Publish the JointState message + self.get_logger().info(f"Publishing arm positions: {joint_state_msg}") + self.arm_publisher_.publish(joint_state_msg) + + # Sleep to simulate time progression + time.sleep(0.1) # Sleep to match the timer period (0.1 seconds) + + # Update the current positions to the desired positions after the movement is complete + self.current_positions = desired_positions + +def main(args=None): + rclpy.init(args=args) + + if len(args) > 1: + joints =args[1] + wheel_node = ArmController(joints) + wheel_node.get_logger().info("ARGUMENTS:: {}".format(joints)) + + rclpy.spin(wheel_node) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + wheel_node.destroy_node() + + # else: + # wheel_node.get_logger().warn("JOINTS not provided, exiting..") + + rclpy.shutdown() + +if __name__ == '__main__': + main(sys.argv) \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/mast_joint_trajectory_controller.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/mast_joint_trajectory_controller.py new file mode 100755 index 00000000..6c00afde --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/mast_joint_trajectory_controller.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 + +import rclpy +from rclpy.node import Node +from builtin_interfaces.msg import Duration + +from std_msgs.msg import String, Float64 +from sensor_msgs.msg import JointState +from std_srvs.srv import Empty +import time + +import sys + + +class MastArmController(Node): + + def __init__(self, joints): + super().__init__('mast_joint_trajectory_controller') + self.get_logger().info("Initializing mast_joint_trajectory_controller node...") + + self.joints_ = joints.split(",") + + # Publisher for JointState + self.mast_publisher_ = self.create_publisher(JointState, '/mast_joint_state_controller/commands', 10) + + # Services for controlling the mast + self.mast_open_srv = self.create_service(Empty, 'mast_open', self.mast_open_callback) + self.mast_close_srv = self.create_service(Empty, 'mast_close', self.mast_close_callback) + self.mast_rotate_srv = self.create_service(Empty, 'mast_rotate', self.mast_rotate_callback) + + # Retain the current joint positions + self.current_positions = [0.0, 0.0, 0.0] # Initialize with default positions + self.get_logger().info("mast_joint_trajectory_controller node initialized and ready.") + + def mast_open_callback(self, request, response): + desired_positions = [0.0, -0.5, 0.0] + self.move_mast(desired_positions, duration=1.0) + return response + + def mast_close_callback(self, request, response): + desired_positions = [1.57, -1.57, 0.0] + self.move_mast(desired_positions, duration=1.0) + return response + + def mast_rotate_callback(self, request, response): + # Sequence of positions to rotate the mast + sequence = [ + ([0.0, -1.57, 0.0], 2.0), + ([0.0, -3.14, 0.0], 2.0), + ([0.0, -6.28, 0.0], 2.0) + ] + + for desired_positions, duration in sequence: + self.move_mast(desired_positions, duration) + + return response + + def move_mast(self, desired_positions, duration): + steps = int(duration / 0.01) # Number of steps based on timer period (0.1s) + + # Calculate the incremental step size for each position + increments = [ + (desired_positions[i] - self.current_positions[i]) / steps + for i in range(len(self.current_positions)) + ] + + # Gradually update positions over the specified duration + for step in range(steps): + self.current_positions = [ + self.current_positions[i] + increments[i] + for i in range(len(self.current_positions)) + ] + + # Create JointState message + joint_state_msg = JointState() + # joint_state_msg.name = ["mast_p_joint", "mast_02_joint", "mast_cameras_joint"] + joint_state_msg.name = self.joints_ + joint_state_msg.position = self.current_positions + + # Publish the JointState message + self.get_logger().info(f"Publishing mast positions: {joint_state_msg}") + self.mast_publisher_.publish(joint_state_msg) + + # Sleep to simulate time progression + time.sleep(0.1) # Sleep to match the timer period (0.1 seconds) + + +def main(args=None): + rclpy.init(args=args) + + if len(args) > 1: + joints =args[1] + wheel_node = MastArmController(joints) + wheel_node.get_logger().info("ARGUMENTS:: {}".format(joints)) + + rclpy.spin(wheel_node) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + wheel_node.destroy_node() + + # else: + # wheel_node.get_logger().warn("JOINTS not provided, exiting..") + + rclpy.shutdown() + +if __name__ == '__main__': + main(sys.argv) \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/run_isaac_demo.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/run_isaac_demo.py new file mode 100755 index 00000000..d9936cd8 --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/run_isaac_demo.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + + +import rclpy +from rclpy.node import Node + +from geometry_msgs.msg import Twist +from std_srvs.srv import Empty + + +# A node for performing combination of motions from different moving parts of the Curiosity rover. +class RunDemo(Node): + def __init__(self) -> None: + super().__init__('run_node') + self.motion_publisher_ = self.create_publisher(Twist, '/cmd_vel', 10) + self.forward_srv = self.create_service(Empty, 'move_forward', self.move_forward_callback) + self.stop_srv = self.create_service(Empty, 'move_stop', self.move_stop_callback) + self.left_srv = self.create_service(Empty, 'turn_left', self.turn_left_callback) + self.right_srv = self.create_service(Empty, 'turn_right', self.turn_right_callback) + self.stopped = True + + timer_period = 0.1 + self.timer = self.create_timer(timer_period, self.timer_callback) + + self.curr_action = Twist() + + def timer_callback(self): + if (not self.stopped): + self.motion_publisher_.publish(self.curr_action) + + def move_forward_callback(self, request, response): + self.get_logger().info("Moving forward") + action = Twist() + action.linear.x = 2.0 + self.curr_action = action + self.stopped = False + return response + + def move_stop_callback(self, request, response): + # stop timer from publishing + self.stopped = True + self.get_logger().info("Stopping") + self.curr_action = Twist() + # publish once to ensure we stop + self.motion_publisher_.publish(self.curr_action) + return response + + def turn_left_callback(self, request, response): + self.get_logger().info("Turning left") + action = Twist() + action.linear.x = 1.0 + action.angular.z = 0.4 + self.curr_action = action + self.stopped = False + return response + + def turn_right_callback(self, request, response): + self.get_logger().info("Turning right") + self.stopped = False + action = Twist() + action.linear.x = 1.0 + action.angular.z = -0.4 + self.curr_action = action + self.stopped = False + return response + + +def main(args=None): + rclpy.init(args=args) + + run_demo = RunDemo() + + rclpy.spin(run_demo) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + run_demo.destroy_node() + rclpy.shutdown() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/steer_position_controller.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/steer_position_controller.py new file mode 100755 index 00000000..a262a79c --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/steer_position_controller.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 + +from pickle import FALSE +import rclpy +from rclpy.node import Node +from builtin_interfaces.msg import Duration + +import rclpy.time +from sensor_msgs.msg import JointState +from geometry_msgs.msg import Twist +import math + +import sys, time + + +class SteerController(Node): + + def __init__(self, joints): + super().__init__('steer_position_controller') + + self.joints_ = joints.split(",") + + # self.get_logger().info("TESTING STEER...") + self.steer_publisher_ = self.create_publisher(JointState, '/steer_position_controller/commands', 10) + + timer_period = 0.1 # seconds + self.timer = self.create_timer(timer_period, self.timer_callback) + + + self.vel_sub = self.create_subscription(Twist, '/cmd_vel', self.vel_callback, 10) + self.curr_vel = Twist() + self.last_vel = Twist() + self.should_steer = False + + def vel_callback(self, msg): + # self.get_logger().info("CMD_VEL callback") + if abs(self.last_vel.angular.z - self.curr_vel.angular.z) > 0.01 and self.should_steer is False: + self.last_vel = Twist() + self.last_vel.linear.x = self.curr_vel.linear.x + self.last_vel.angular.z = self.curr_vel.angular.z + self.should_steer = True + + self.curr_vel = msg + + + def map_angular_to_steering(self, angular_speed) -> float: + if abs(angular_speed) < 1e-3: + return 0.0 + + #max 0.6 min -0.6 + angular_speed = min(0.6, max(angular_speed, -0.6)) + return (angular_speed/abs(angular_speed))*(-25 * abs(angular_speed) + 17.5) + + + def set_steering(self, turn_rad): + # Desired steering position using JointState message + target_steer = JointState() + + # target_steer.header.stamp = self.get_clock().now().to_msg() + target_steer.name = self.joints_ + + # Retain the last known positions + if not hasattr(self, 'current_positions'): + # Initialize starting positions if not set + self.current_positions = [0.0, 0.0, 0.0, 0.0] + + if abs(turn_rad) < 1e-3: + desired_positions = [0.0, 0.0, 0.0, 0.0] + else: + R = abs(turn_rad) #Turning radius + + L = 2.08157 #Chassis Length + T = 1.53774 #Chassis Width + + alpha_i = math.atan(L/(R - (T/2))) + alpha_o = math.atan(L/(R + (T/2))) + + if alpha_i > 0.6: + alpha_i = 0.6 + + if alpha_o > 0.6: + alpha_o = 0.6 + + alpha_i = round(alpha_i, 2) + alpha_o = round(alpha_o, 2) + + if turn_rad > 0.0: + desired_positions = [alpha_i, -alpha_i, alpha_o, -alpha_o] + else: + desired_positions = [-alpha_o, alpha_o, -alpha_i, alpha_i] + + + # Time duration to reach desired positions + duration = 1.0 # 1 second + steps = int(duration / 0.02) # Number of steps based on timer period + + # Calculate the incremental step size for each position + increments = [ + (desired_positions[i] - self.current_positions[i]) / steps + for i in range(len(self.current_positions)) + ] + + for step in range(steps): + # Update current positions by adding the increments + self.current_positions = [ + self.current_positions[i] + increments[i] + for i in range(len(self.current_positions)) + ] + target_steer.position = self.current_positions + self.get_logger().info(f"Publishing steering positions: {target_steer}") + self.steer_publisher_.publish(target_steer) + + # Sleep to simulate time progression + time.sleep(0.1) # Adjust the sleep time to match the timer period + + + def timer_callback(self): + + if self.should_steer: + steering_val = self.map_angular_to_steering(self.curr_vel.angular.z) + self.set_steering(steering_val) + self.should_steer = False + + +def main(args=None): + rclpy.init(args=args) + + if len(args) > 1: + joints =args[1] + steer_node = SteerController(joints) + steer_node.get_logger().info("ARGUMENTS:: {}".format(joints)) + + rclpy.spin(steer_node) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + steer_node.destroy_node() + + # else: + # wheel_node.get_logger().warn("JOINTS not provided, exiting..") + + rclpy.shutdown() + +if __name__ == '__main__': + main(sys.argv) \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/wheel_tree_position_controller.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/wheel_tree_position_controller.py new file mode 100755 index 00000000..a175846f --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/wheel_tree_position_controller.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +from pickle import FALSE +import rclpy +from rclpy.node import Node +# from builtin_interfaces.msg import Duration + +from sensor_msgs.msg import JointState + +import sys + +class WheelTreeController(Node): + + def __init__(self, joints): + super().__init__('wheel_tree_position_controller') + + self.joints_ = joints.split(",") + + self.suspension_publisher_ = self.create_publisher(JointState, '/wheel_tree_position_controller/commands',10) + timer_period = 0.1 # seconds + self.timer = self.create_timer(timer_period, self.timer_callback) + + def set_suspension(self, sus_val=None): + target_val = JointState() + if sus_val is None: + target_val.effort = [0.3,-0.1,0.3,-0.1] + target_val.name = self.joints_ + + self.suspension_publisher_.publish(target_val) + + + def timer_callback(self): + self.set_suspension() + +def main(args=None): + rclpy.init(args=args) + + if len(args) > 1: + joints =args[1] + wheel_node = WheelTreeController(joints) + wheel_node.get_logger().info("ARGUMENTS:: {}".format(joints)) + + rclpy.spin(wheel_node) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + wheel_node.destroy_node() + + # else: + # wheel_node.get_logger().warn("JOINTS not provided, exiting..") + + rclpy.shutdown() + +if __name__ == '__main__': + main(sys.argv) \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/wheel_velocity_controller.py b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/wheel_velocity_controller.py new file mode 100755 index 00000000..a92dbe8b --- /dev/null +++ b/mars_rover_nvidia_isaac/mars_rover_nvidia_isaac/nodes/wheel_velocity_controller.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +from pickle import FALSE +import rclpy +from rclpy.node import Node +from builtin_interfaces.msg import Duration + +# from std_msgs.msg import String, Float64MultiArray +import rclpy.time +from sensor_msgs.msg import JointState +from geometry_msgs.msg import Twist +import math + +import sys + +class WheelController(Node): +# class WheelController(): + + # def __init__(self, joints, node_handle): + def __init__(self, joints): + super().__init__('wheel_velocity_controller') + + self.joints_ = joints.split(",") + # self.nh_ = node_handle + + + # self.nh_.get_logger().info("TESTING 123...") + self.wheel_publisher_ = self.create_publisher(JointState, '/wheel_velocity', 10) + + timer_period = 0.1 # seconds + self.timer = self.create_timer(timer_period, self.timer_callback) + + + self.vel_sub = self.create_subscription(Twist, '/cmd_vel', self.vel_callback, 10) + self.curr_vel = Twist() + # self.last_vel = Twist() + + def vel_callback(self, msg): + # if abs(self.last_vel.angular.z - self.curr_vel.angular.z) > 0.01 and self.should_steer is False: + # self.last_vel = Twist() + # self.last_vel.linear.x = self.curr_vel.linear.x + # self.last_vel.angular.z = self.curr_vel.angular.z + # self.should_steer = True + + self.curr_vel = msg + + def set_wheel_common_speed(self, vel): + + target_state = JointState() + + # target_state.header.stamp = self.get_clock().now() + target_state.name = self.joints_ + target_state.velocity = [vel, vel*1.5, vel, -vel, -vel*1.5, -vel] + + + # self.nh_.get_logger().info(f'Publishing: "{target_state}"') + self.wheel_publisher_.publish(target_state) + + def timer_callback(self): + self.set_wheel_common_speed(self.curr_vel.linear.x) + + +def main(args=None): + rclpy.init(args=args) + + if len(args) > 1: + joints =args[1] + wheel_node = WheelController(joints) + wheel_node.get_logger().info("ARGUMENTS:: {}".format(joints)) + + rclpy.spin(wheel_node) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + wheel_node.destroy_node() + + # else: + # wheel_node.get_logger().warn("JOINTS not provided, exiting..") + + rclpy.shutdown() + +if __name__ == '__main__': + main(sys.argv) \ No newline at end of file diff --git a/mars_rover_nvidia_isaac/package.xml b/mars_rover_nvidia_isaac/package.xml new file mode 100644 index 00000000..95940c88 --- /dev/null +++ b/mars_rover_nvidia_isaac/package.xml @@ -0,0 +1,18 @@ + + + + mars_rover_nvidia_isaac + 0.0.0 + TODO: Package description + abhinesh + TODO: License declaration + + ament_copyright + ament_flake8 + ament_pep257 + python3-pytest + + + ament_cmake + + diff --git a/mars_rover_teleop/CMakeLists.txt b/mars_rover_teleop/CMakeLists.txt new file mode 100644 index 00000000..59327dad --- /dev/null +++ b/mars_rover_teleop/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.8) +project(mars_rover_teleop) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_AUTOMOC ON) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(rviz_common REQUIRED) +find_package(rviz_rendering REQUIRED) +find_package(rclcpp REQUIRED) +find_package(std_srvs REQUIRED) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # comment the line when a copyright and license is added to all source files + set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # comment the line when this package is in a git repo and when + # a copyright and license is added to all source files + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +# Add RViz plugin +add_library(${PROJECT_NAME} SHARED + src/mars_rover_teleop.cpp +) + +target_link_libraries(${PROJECT_NAME} + rviz_common::rviz_common + rviz_rendering::rviz_rendering + rclcpp::rclcpp + pluginlib::pluginlib +) + +ament_target_dependencies(${PROJECT_NAME} + "rviz_common" + "rviz_rendering" + "rclcpp" + "std_srvs" + "pluginlib" +) + +install(TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +install(DIRECTORY + config + DESTINATION share/${PROJECT_NAME} +) + +install(FILES plugin_description.xml + DESTINATION share/${PROJECT_NAME} +) + +pluginlib_export_plugin_description_file(rviz_common plugin_description.xml) + +ament_export_libraries(${PROJECT_NAME}) + +ament_package() diff --git a/mars_rover_teleop/README.md b/mars_rover_teleop/README.md new file mode 100644 index 00000000..3935a335 --- /dev/null +++ b/mars_rover_teleop/README.md @@ -0,0 +1,11 @@ +# Mars Rover Teleop RViz2 Plugin + +1. This package provides an rviz2 plugin for tele-operation of the curiosity rover with **mars_rover_nvidia_isaac package** +2. Config file **config > rviz_with_teleop.rviz** loads the plugin at bottom left rocation in RViz2. + ```bash + rviz2 -d + ``` +3. Config file **config > rviz_teleop_sensors.rviz** loads RViz2 with the teleop plugin, camera window as well as lidar data. + ```bash + rviz2 -d + ``` \ No newline at end of file diff --git a/mars_rover_teleop/config/rviz_teleop_sensors.rviz b/mars_rover_teleop/config/rviz_teleop_sensors.rviz new file mode 100644 index 00000000..fa73aa81 --- /dev/null +++ b/mars_rover_teleop/config/rviz_teleop_sensors.rviz @@ -0,0 +1,236 @@ +Panels: + - Class: rviz_common/Displays + Help Height: 0 + Name: Displays + Property Tree Widget: + Expanded: + - /Global Options1 + - /Status1 + - /TF1/Frames1 + - /TF1/Tree1 + Splitter Ratio: 0.5 + Tree Height: 140 + - Class: rviz_common/Selection + Name: Selection + - Class: rviz_common/Tool Properties + Expanded: + - /2D Goal Pose1 + - /Publish Point1 + Name: Tool Properties + Splitter Ratio: 0.5886790156364441 + - Class: rviz_common/Views + Expanded: + - /Current View1 + Name: Views + Splitter Ratio: 0.5 + - Class: rviz_common/Time + Experimental: false + Name: Time + SyncMode: 0 + SyncSource: LaserScan + - Class: MarsRoverTeleop + Name: MarsRoverTeleop +Visualization Manager: + Class: "" + Displays: + - Alpha: 0.5 + Cell Size: 1 + Class: rviz_default_plugins/Grid + Color: 160; 160; 164 + Enabled: true + Line Style: + Line Width: 0.029999999329447746 + Value: Lines + Name: Grid + Normal Cell Count: 0 + Offset: + X: 0 + Y: 0 + Z: 0 + Plane: XY + Plane Cell Count: 10 + Reference Frame: + Value: true + - Class: rviz_default_plugins/Image + Enabled: true + Max Value: 1 + Median window: 5 + Min Value: 0 + Name: Image + Normalize Range: true + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /image_raw + Value: true + - Alpha: 1 + Autocompute Intensity Bounds: true + Autocompute Value Bounds: + Max Value: 10 + Min Value: -10 + Value: true + Axis: Z + Channel Name: intensity + Class: rviz_default_plugins/LaserScan + Color: 255; 255; 255 + Color Transformer: Intensity + Decay Time: 0 + Enabled: true + Invert Rainbow: false + Max Color: 255; 255; 255 + Max Intensity: 6 + Min Color: 0; 0; 0 + Min Intensity: 0 + Name: LaserScan + Position Transformer: XYZ + Selectable: true + Size (Pixels): 2 + Size (m): 0.009999999776482582 + Style: Points + Topic: + Depth: 5 + Durability Policy: Volatile + Filter size: 10 + History Policy: Keep Last + Reliability Policy: Reliable + Value: /scan + Use Fixed Frame: true + Use rainbow: true + Value: true + - Alpha: 1 + Class: rviz_default_plugins/RobotModel + Collision Enabled: false + Description File: "" + Description Source: Topic + Description Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: "" + Enabled: true + Links: + All Links Enabled: true + Expand Joint Details: false + Expand Link Details: false + Expand Tree: false + Link Tree Style: "" + Mass Properties: + Inertia: false + Mass: false + Name: RobotModel + TF Prefix: "" + Update Interval: 0 + Value: true + Visual Enabled: true + - Class: rviz_default_plugins/TF + Enabled: false + Frame Timeout: 15 + Frames: + All Enabled: true + Marker Scale: 1 + Name: TF + Show Arrows: true + Show Axes: true + Show Names: true + Tree: + {} + Update Interval: 0 + Value: false + - Class: rviz_default_plugins/Axes + Enabled: true + Length: 1 + Name: Axes + Radius: 0.10000000149011612 + Reference Frame: + Value: true + Enabled: true + Global Options: + Background Color: 48; 48; 48 + Fixed Frame: base_footprint + Frame Rate: 30 + Name: root + Tools: + - Class: rviz_default_plugins/Interact + Hide Inactive Objects: true + - Class: rviz_default_plugins/MoveCamera + - Class: rviz_default_plugins/Select + - Class: rviz_default_plugins/FocusCamera + - Class: rviz_default_plugins/Measure + Line color: 128; 128; 0 + - Class: rviz_default_plugins/SetInitialPose + Covariance x: 0.25 + Covariance y: 0.25 + Covariance yaw: 0.06853891909122467 + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /initialpose + - Class: rviz_default_plugins/SetGoal + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /goal_pose + - Class: rviz_default_plugins/PublishPoint + Single click: true + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /clicked_point + Transformation: + Current: + Class: rviz_default_plugins/TF + Value: true + Views: + Current: + Class: rviz_default_plugins/Orbit + Distance: 76.05075073242188 + Enable Stereo Rendering: + Stereo Eye Separation: 0.05999999865889549 + Stereo Focal Distance: 1 + Swap Stereo Eyes: false + Value: false + Focal Point: + X: 0.9532128572463989 + Y: -7.463510513305664 + Z: 3.9572255611419678 + Focal Shape Fixed Size: false + Focal Shape Size: 0.05000000074505806 + Invert Z Axis: false + Name: Current View + Near Clip Distance: 0.009999999776482582 + Pitch: 0.7403982281684875 + Target Frame: + Value: Orbit (rviz) + Yaw: 3.1803994178771973 + Saved: ~ +Window Geometry: + Displays: + collapsed: false + Height: 773 + Hide Left Dock: false + Hide Right Dock: false + Image: + collapsed: false + MarsRoverTeleop: + collapsed: false + QMainWindow State: 000000ff00000000fd00000004000000000000023700000267fc020000000bfb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000000c9000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000001e004d0061007200730052006f00760065007200540065006c0065006f0070010000010c0000009e0000009e00fffffffb0000000c00430061006d00650072006100000002f3000000bf0000000000000000fb0000000a0049006d00610067006501000001b0000000f40000002800ffffff000000010000010f00000267fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073010000003d00000267000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000005a00000003efc0100000002fb0000000800540069006d00650100000000000005a0000002fb00fffffffb0000000800540069006d006501000000000000045000000000000000000000024e0000026700000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 + Selection: + collapsed: false + Time: + collapsed: false + Tool Properties: + collapsed: false + Views: + collapsed: false + Width: 1440 + X: 2196 + Y: 113 diff --git a/mars_rover_teleop/config/rviz_with_teleop.rviz b/mars_rover_teleop/config/rviz_with_teleop.rviz new file mode 100644 index 00000000..6b6e5f46 --- /dev/null +++ b/mars_rover_teleop/config/rviz_with_teleop.rviz @@ -0,0 +1,137 @@ +Panels: + - Class: rviz_common/Displays + Help Height: 78 + Name: Displays + Property Tree Widget: + Expanded: + - /Global Options1 + - /Status1 + Splitter Ratio: 0.5 + Tree Height: 608 + - Class: rviz_common/Selection + Name: Selection + - Class: rviz_common/Tool Properties + Expanded: + - /2D Goal Pose1 + - /Publish Point1 + Name: Tool Properties + Splitter Ratio: 0.5886790156364441 + - Class: rviz_common/Views + Expanded: + - /Current View1 + Name: Views + Splitter Ratio: 0.5 + - Class: rviz_common/Time + Experimental: false + Name: Time + SyncMode: 0 + SyncSource: "" + - Class: MarsRoverTeleop + Name: MarsRoverTeleop +Visualization Manager: + Class: "" + Displays: + - Alpha: 0.5 + Cell Size: 1 + Class: rviz_default_plugins/Grid + Color: 160; 160; 164 + Enabled: true + Line Style: + Line Width: 0.029999999329447746 + Value: Lines + Name: Grid + Normal Cell Count: 0 + Offset: + X: 0 + Y: 0 + Z: 0 + Plane: XY + Plane Cell Count: 10 + Reference Frame: + Value: true + Enabled: true + Global Options: + Background Color: 48; 48; 48 + Fixed Frame: map + Frame Rate: 30 + Name: root + Tools: + - Class: rviz_default_plugins/Interact + Hide Inactive Objects: true + - Class: rviz_default_plugins/MoveCamera + - Class: rviz_default_plugins/Select + - Class: rviz_default_plugins/FocusCamera + - Class: rviz_default_plugins/Measure + Line color: 128; 128; 0 + - Class: rviz_default_plugins/SetInitialPose + Covariance x: 0.25 + Covariance y: 0.25 + Covariance yaw: 0.06853891909122467 + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /initialpose + - Class: rviz_default_plugins/SetGoal + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /goal_pose + - Class: rviz_default_plugins/PublishPoint + Single click: true + Topic: + Depth: 5 + Durability Policy: Volatile + History Policy: Keep Last + Reliability Policy: Reliable + Value: /clicked_point + Transformation: + Current: + Class: rviz_default_plugins/TF + Value: true + Views: + Current: + Class: rviz_default_plugins/Orbit + Distance: 10 + Enable Stereo Rendering: + Stereo Eye Separation: 0.05999999865889549 + Stereo Focal Distance: 1 + Swap Stereo Eyes: false + Value: false + Focal Point: + X: 0 + Y: 0 + Z: 0 + Focal Shape Fixed Size: true + Focal Shape Size: 0.05000000074505806 + Invert Z Axis: false + Name: Current View + Near Clip Distance: 0.009999999776482582 + Pitch: 0.785398006439209 + Target Frame: + Value: Orbit (rviz) + Yaw: 0.785398006439209 + Saved: ~ +Window Geometry: + Displays: + collapsed: false + Height: 1136 + Hide Left Dock: false + Hide Right Dock: false + MarsRoverTeleop: + collapsed: false + QMainWindow State: 000000ff00000000fd000000040000000000000156000003d2fc0200000009fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000002eb000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000001e004d0061007200730052006f00760065007200540065006c0065006f0070010000032e000000e10000009e00ffffff000000010000010f000003d2fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073010000003d000003d2000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000039d0000003efc0100000002fb0000000800540069006d006501000000000000039d000002fb00fffffffb0000000800540069006d006501000000000000045000000000000000000000012c000003d200000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 + Selection: + collapsed: false + Time: + collapsed: false + Tool Properties: + collapsed: false + Views: + collapsed: false + Width: 925 + X: 995 + Y: 27 diff --git a/mars_rover_teleop/package.xml b/mars_rover_teleop/package.xml new file mode 100644 index 00000000..4597e1e0 --- /dev/null +++ b/mars_rover_teleop/package.xml @@ -0,0 +1,24 @@ + + + + mars_rover_teleop + 0.0.0 + TODO: Package description + puneet + TODO: License declaration + + ament_cmake + + rviz_common + rviz_rendering + rclcpp + std_srvs + pluginlib + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/mars_rover_teleop/plugin_description.xml b/mars_rover_teleop/plugin_description.xml new file mode 100644 index 00000000..9c1b99ae --- /dev/null +++ b/mars_rover_teleop/plugin_description.xml @@ -0,0 +1,7 @@ + + + Custom teleoperation panel for controlling Mars Rover. + + diff --git a/mars_rover_teleop/src/mars_rover_teleop.cpp b/mars_rover_teleop/src/mars_rover_teleop.cpp new file mode 100644 index 00000000..00001cd6 --- /dev/null +++ b/mars_rover_teleop/src/mars_rover_teleop.cpp @@ -0,0 +1,148 @@ +#define RVIZ_PLUGINLIB_EXPORT __attribute__((visibility("default"))) + +#include +#include +#include +#include +#include + +class MarsRoverTeleop : public rviz_common::Panel +{ + Q_OBJECT +public: + MarsRoverTeleop(QWidget* parent = nullptr) + : rviz_common::Panel(parent) + { + // Initialize ROS node + node_ = std::make_shared("mars_rover_teleop_node"); + + // Service clients for Wheel Movement + forward_srv_ = node_->create_client("move_forward"); + stop_srv_ = node_->create_client("move_stop"); + left_srv_ = node_->create_client("turn_left"); + right_srv_ = node_->create_client("turn_right"); + + // Service clients for Arm Movement + open_arm_srv_ = node_->create_client("open_arm"); + close_arm_srv_ = node_->create_client("close_arm"); + + // Service clients for Mast Movement + mast_open_srv_ = node_->create_client("mast_open"); + mast_close_srv_ = node_->create_client("mast_close"); + mast_rotate_srv_ = node_->create_client("mast_rotate"); + + // Create buttons for Wheel Movement + QPushButton* forward_button = new QPushButton("Forward"); + QPushButton* stop_button = new QPushButton("Stop"); + QPushButton* left_button = new QPushButton("Left"); + QPushButton* right_button = new QPushButton("Right"); + + // Create buttons for Arm Movement + QPushButton* open_arm_button = new QPushButton("Open Arm"); + QPushButton* close_arm_button = new QPushButton("Close Arm"); + + // Create buttons for Mast Movement + QPushButton* mast_open_button = new QPushButton("Mast Open"); + QPushButton* mast_close_button = new QPushButton("Mast Close"); + QPushButton* mast_rotate_button = new QPushButton("Mast Rotate"); + + // Create a grid layout to arrange buttons + QGridLayout* layout = new QGridLayout; + + // Add Wheel Movement buttons + layout->addWidget(forward_button, 0, 1); // Forward button on top + layout->addWidget(left_button, 1, 0); // Left button on the left + layout->addWidget(stop_button, 1, 1); // Stop button in the center + layout->addWidget(right_button, 1, 2); // Right button on the right + + // Add Arm Movement buttons + layout->addWidget(open_arm_button, 2, 0); // Open Arm button + layout->addWidget(close_arm_button, 2, 1); // Close Arm button + + // Add Mast Movement buttons + layout->addWidget(mast_open_button, 3, 0); // Mast Open button + layout->addWidget(mast_close_button, 3, 1); // Mast Close button + layout->addWidget(mast_rotate_button, 3, 2); // Mast Rotate button + + setLayout(layout); + + // Connect buttons to their respective service calls + connect(forward_button, &QPushButton::clicked, this, &MarsRoverTeleop::callMoveForward); + connect(stop_button, &QPushButton::clicked, this, &MarsRoverTeleop::callMoveStop); + connect(left_button, &QPushButton::clicked, this, &MarsRoverTeleop::callTurnLeft); + connect(right_button, &QPushButton::clicked, this, &MarsRoverTeleop::callTurnRight); + + connect(open_arm_button, &QPushButton::clicked, this, &MarsRoverTeleop::callOpenArm); + connect(close_arm_button, &QPushButton::clicked, this, &MarsRoverTeleop::callCloseArm); + + connect(mast_open_button, &QPushButton::clicked, this, &MarsRoverTeleop::callMastOpen); + connect(mast_close_button, &QPushButton::clicked, this, &MarsRoverTeleop::callMastClose); + connect(mast_rotate_button, &QPushButton::clicked, this, &MarsRoverTeleop::callMastRotate); + } + + virtual ~MarsRoverTeleop() override = default; // virtual destructor + +private Q_SLOTS: + void callMoveForward() { + auto request = std::make_shared(); + forward_srv_->async_send_request(request); + } + + void callMoveStop() { + auto request = std::make_shared(); + stop_srv_->async_send_request(request); + } + + void callTurnLeft() { + auto request = std::make_shared(); + left_srv_->async_send_request(request); + } + + void callTurnRight() { + auto request = std::make_shared(); + right_srv_->async_send_request(request); + } + + void callOpenArm() { + auto request = std::make_shared(); + open_arm_srv_->async_send_request(request); + } + + void callCloseArm() { + auto request = std::make_shared(); + close_arm_srv_->async_send_request(request); + } + + void callMastOpen() { + auto request = std::make_shared(); + mast_open_srv_->async_send_request(request); + } + + void callMastClose() { + auto request = std::make_shared(); + mast_close_srv_->async_send_request(request); + } + + void callMastRotate() { + auto request = std::make_shared(); + mast_rotate_srv_->async_send_request(request); + } + +private: + rclcpp::Node::SharedPtr node_; + rclcpp::Client::SharedPtr forward_srv_; + rclcpp::Client::SharedPtr stop_srv_; + rclcpp::Client::SharedPtr left_srv_; + rclcpp::Client::SharedPtr right_srv_; + rclcpp::Client::SharedPtr open_arm_srv_; + rclcpp::Client::SharedPtr close_arm_srv_; + rclcpp::Client::SharedPtr mast_open_srv_; + rclcpp::Client::SharedPtr mast_close_srv_; + rclcpp::Client::SharedPtr mast_rotate_srv_; +}; + +// Export as plugin +#include +PLUGINLIB_EXPORT_CLASS(MarsRoverTeleop, rviz_common::Panel) + +#include "mars_rover_teleop.moc"