From 4f82c33a84afe0d0e645e9740b28985ddeefc7db Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Thu, 28 Mar 2024 19:54:22 -0400 Subject: [PATCH] usage & demo --- README.md | 4 +- ros_web_api_bellande_step/CMakeLists.txt | 39 +++++++++++++++++++ ros_web_api_bellande_step/package.xml | 37 ++++++++++++++++++ .../src/bellande_step_api_2d.py | 39 +++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 ros_web_api_bellande_step/CMakeLists.txt create mode 100644 ros_web_api_bellande_step/package.xml create mode 100644 ros_web_api_bellande_step/src/bellande_step_api_2d.py diff --git a/README.md b/README.md index 93e6913..5a81ec3 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# Web-ROS-API +# Bellande Web ROS/ROS2 API + +## - Functionality is to use Bellande API and Models for different functionality related to computer science diff --git a/ros_web_api_bellande_step/CMakeLists.txt b/ros_web_api_bellande_step/CMakeLists.txt new file mode 100644 index 0000000..3dc542f --- /dev/null +++ b/ros_web_api_bellande_step/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.8) +project(ros_web_api_bellande_step) + +## Compile as C++11, supported in ROS Kinetic and newer +add_compile_options(-std=c++11) + +# Find ROS +if($ENV{ROS_VERSION} EQUAL 1) + find_package(catkin REQUIRED COMPONENTS + roscpp + rospy + ) +else() + find_package(ament_cmake REQUIRED COMPONENTS + rclcpp + rclpy + ) +endif() + +if($ENV{ROS_VERSION} EQUAL 1) + catkin_package( + INCLUDE_DIRS + LIBRARIES ${PROJECT_NAME} + CATKIN_DEPENDS + roscpp + rospy + ) +endif() + +# Install Python scripts, configuration files, and launch files +if($ENV{ROS_VERSION} EQUAL "1") + install(PROGRAMS src/bellande_step_api_2d.py DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}) + install(DIRECTORY config/ DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config) + install(DIRECTORY launch/ DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch) +elseif($ENV{ROS_VERSION} EQUAL "2") + install(PROGRAMS src/bellande_step_api_2d.py DESTINATION lib/${PROJECT_NAME}) + install(DIRECTORY config/ DESTINATION share/${PROJECT_NAME}/config) + install(DIRECTORY launch/ DESTINATION share/${PROJECT_NAME}/launch) +endif() diff --git a/ros_web_api_bellande_step/package.xml b/ros_web_api_bellande_step/package.xml new file mode 100644 index 0000000..8d89adb --- /dev/null +++ b/ros_web_api_bellande_step/package.xml @@ -0,0 +1,37 @@ + + + ros_web_api_bellande_step + 0.0.1 + Bellande ROS/ROS2 package with a JSON config file for making HTTP requests + Ronaldson Bellande + Ronaldson Bellande + Apache License 2.0 + + + catkin + + roscpp + rospy + + roscpp + rospy + + roscpp + rospy + + + ament_cmake + + rclcpp + rclpy + + rclcpp + rclpy + + rclcpp + rclpy + + + + + diff --git a/ros_web_api_bellande_step/src/bellande_step_api_2d.py b/ros_web_api_bellande_step/src/bellande_step_api_2d.py new file mode 100644 index 0000000..a815209 --- /dev/null +++ b/ros_web_api_bellande_step/src/bellande_step_api_2d.py @@ -0,0 +1,39 @@ +import json +import requests +import os + +# Get the parameters from the launch file +x1 = float(os.getenv('x1')) +y1 = float(os.getenv('y1')) +x2 = float(os.getenv('x2')) # Read x2 from launch file +y2 = float(os.getenv('y2')) # Read y2 from launch file +limit = int(os.getenv('limit')) + +# URL and endpoint path +url = "https://bellanderoboticssensorsresearchinnovationcenter-kot42qxp.b4a.run" +endpoint_path = "/api/Bellande_Step/bellande_step_2d" + +# JSON payload +payload = { + "node0": {"x": x1, "y": y1}, + "node1": {"x": x2, "y": y2} +} + +# Headers +headers = { + 'accept': 'application/json', + 'Content-Type': 'application/json' +} + +# Make POST request +try: + response = requests.post( + url + endpoint_path + '?limit=' + str(limit), + json=payload, + headers=headers + ) + response.raise_for_status() # Raise an error for unsuccessful responses + data = response.json() + print("Next Step:", data['next_step']) +except requests.exceptions.RequestException as e: + print("Error:", e)