latest pushes
This commit is contained in:
35
ros_web_api_bellande_step/src/bellande_step_api_2d.py
Normal file → Executable file
35
ros_web_api_bellande_step/src/bellande_step_api_2d.py
Normal file → Executable file
@@ -4,19 +4,39 @@ import requests
|
||||
import sys
|
||||
|
||||
def main():
|
||||
# Get the absolute path to the config file
|
||||
config_file_path = os.path.join(os.path.dirname(__file__), '../config/config2d.json')
|
||||
|
||||
# Check if the config file exists
|
||||
if not os.path.exists(config_file_path):
|
||||
print("Config file not found:", config_file_path)
|
||||
return
|
||||
|
||||
# Read configuration from config.json
|
||||
with open(os.path.join(sys.path[0], 'config.json'), 'r') as config_file:
|
||||
with open(config_file_path, 'r') as config_file:
|
||||
config = json.load(config_file)
|
||||
url = config['url']
|
||||
endpoint_path = config['endpoint_path']
|
||||
|
||||
|
||||
# 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'))
|
||||
x1_str = os.getenv('x1')
|
||||
y1_str = os.getenv('y1')
|
||||
x2_str = os.getenv('x2')
|
||||
y2_str = os.getenv('y2')
|
||||
limit_str = os.getenv('limit')
|
||||
|
||||
# Check if any of the environment variables are not set
|
||||
if any(v is None for v in [x1_str, y1_str, x2_str, y2_str, limit_str]):
|
||||
print("One or more required environment variables are not set.")
|
||||
return
|
||||
|
||||
# Convert the parameters to float or int
|
||||
x1 = float(x1_str)
|
||||
y1 = float(y1_str)
|
||||
x2 = float(x2_str)
|
||||
y2 = float(y2_str)
|
||||
limit = int(limit_str)
|
||||
|
||||
# JSON payload
|
||||
payload = {
|
||||
"node0": {"x": x1, "y": y1},
|
||||
@@ -29,6 +49,7 @@ def main():
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
|
||||
# Make POST request
|
||||
try:
|
||||
response = requests.post(
|
||||
|
Reference in New Issue
Block a user