From 48928dc82771f6456d5689d44e856604f68cc54e Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Fri, 29 Mar 2024 00:02:06 -0400 Subject: [PATCH] recal --- .../src/bellande_step_api_2d.py | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) 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 index a815209..d837d4a 100644 --- a/ros_web_api_bellande_step/src/bellande_step_api_2d.py +++ b/ros_web_api_bellande_step/src/bellande_step_api_2d.py @@ -1,39 +1,45 @@ import json -import requests import os +import requests -# 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')) +def main(): + # Read configuration from config.json + with open('config.json', 'r') as config_file: + config = json.load(config_file) + url = config['url'] + endpoint_path = config['endpoint_path'] -# URL and endpoint path -url = "https://bellanderoboticssensorsresearchinnovationcenter-kot42qxp.b4a.run" -endpoint_path = "/api/Bellande_Step/bellande_step_2d" + # Get the parameters from the launch file + x1 = float(os.getenv('x1')) + y1 = float(os.getenv('y1')) + x2 = float(os.getenv('x2')) + y2 = float(os.getenv('y2')) + limit = int(os.getenv('limit')) -# JSON payload -payload = { - "node0": {"x": x1, "y": y1}, - "node1": {"x": x2, "y": y2} -} + # JSON payload + payload = { + "node0": {"x": x1, "y": y1}, + "node1": {"x": x2, "y": y2} + } -# Headers -headers = { - 'accept': 'application/json', - 'Content-Type': 'application/json' -} + # 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) + # 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) + +if __name__ == '__main__': + main()