latest pushes
This commit is contained in:
51
web_api_bellande_extremum_optimization/CMakeLists.txt
Normal file
51
web_api_bellande_extremum_optimization/CMakeLists.txt
Normal file
@@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(web_api_bellande_extremum_optimization)
|
||||
|
||||
# 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_2d_computer_vision_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_2d_computer_vision_api_2d.py DESTINATION lib/${PROJECT_NAME})
|
||||
install(DIRECTORY config/ DESTINATION share/${PROJECT_NAME}/config)
|
||||
install(DIRECTORY launch/ DESTINATION share/${PROJECT_NAME}/launch)
|
||||
endif()
|
3
web_api_bellande_extremum_optimization/README.md
Normal file
3
web_api_bellande_extremum_optimization/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Bellande Search Path Web ROS/ROS2 API Intergration
|
||||
|
||||
[Bellande Search Path](https://github.com/RonaldsonBellande/bellande_robots_step)
|
14
web_api_bellande_extremum_optimization/config/configs.json
Normal file
14
web_api_bellande_extremum_optimization/config/configs.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"url": "https://bellande-robotics-sensors-research-innovation-center.org",
|
||||
"endpoint_path": {
|
||||
"2d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_2d",
|
||||
"3d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_3d",
|
||||
"4d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_4d",
|
||||
"5d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_5d",
|
||||
"6d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_6d",
|
||||
"7d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_7d",
|
||||
"8d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_8d",
|
||||
"9d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_9d",
|
||||
"10d": "/api/Bellande_Extremum_Optimization/bellande_extremum_optimization_10d"
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from launch import LaunchDescription
|
||||
from launch_ros.actions import Node
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
|
||||
|
||||
def ros1_launch_description():
|
||||
# Get command-line arguments
|
||||
args = sys.argv[1:]
|
||||
|
||||
# Construct the ROS 1 launch commandi
|
||||
roslaunch_command = ["roslaunch", "web_api_bellande_step", "bellande_step_api_2d.launch"] + args
|
||||
|
||||
# Execute the launch command
|
||||
subprocess.call(roslaunch_command)
|
||||
|
||||
|
||||
def ros2_launch_description():
|
||||
# Declare launch arguments
|
||||
x1_arg = DeclareLaunchArgument('x1')
|
||||
y1_arg = DeclareLaunchArgument('y1')
|
||||
x2_arg = DeclareLaunchArgument('x2')
|
||||
y2_arg = DeclareLaunchArgument('y2')
|
||||
limit_arg = DeclareLaunchArgument('limit')
|
||||
|
||||
# Create a list to hold all nodes to be launched
|
||||
nodes_to_launch = []
|
||||
|
||||
# ROS2 specific configurations
|
||||
ros_launch_arguments = [
|
||||
x1_arg, y1_arg, x2_arg, y2_arg, limit_arg,
|
||||
]
|
||||
nodes_to_launch.append(Node(
|
||||
package='web_api_bellande_step',
|
||||
executable='bellande_step_api_2d.py',
|
||||
name='bellande_step_api_2d_node',
|
||||
output='screen',
|
||||
parameters=[
|
||||
{'x1': LaunchConfiguration('x1')},
|
||||
{'y1': LaunchConfiguration('y1')},
|
||||
{'x2': LaunchConfiguration('x2')},
|
||||
{'y2': LaunchConfiguration('y2')},
|
||||
{'limit': LaunchConfiguration('limit')},
|
||||
],
|
||||
))
|
||||
|
||||
# Return the LaunchDescription containing all nodes and arguments
|
||||
return LaunchDescription(ros_launch_arguments + nodes_to_launch)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ros_version = os.getenv("ROS_VERSION")
|
||||
if ros_version == "1":
|
||||
ros1_launch_description()
|
||||
elif ros_version == "2":
|
||||
ros2_launch_description()
|
||||
else:
|
||||
print("Unsupported ROS version. Please set the ROS_VERSION environment variable to '1' for ROS 1 or '2' for ROS 2.")
|
||||
sys.exit(1)
|
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
|
||||
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.
|
||||
-->
|
||||
<launch>
|
||||
<arg name="x1" />
|
||||
<arg name="y1" />
|
||||
<arg name="x2" />
|
||||
<arg name="y2" />
|
||||
<arg name="limit" />
|
||||
|
||||
<node pkg="web_api_bellande_step" type="bellande_step_api_2d.py"
|
||||
name="bellande_step_api_2d_node" output="screen">
|
||||
<param name="x1" value="$(arg x1)" />
|
||||
<param name="y1" value="$(arg y1)" />
|
||||
<param name="x2" value="$(arg x2)" />
|
||||
<param name="y2" value="$(arg y2)" />
|
||||
<param name="limit" value="$(arg limit)" />
|
||||
</node>
|
||||
</launch>
|
53
web_api_bellande_extremum_optimization/package.xml
Normal file
53
web_api_bellande_extremum_optimization/package.xml
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<package format="3">
|
||||
<name>web_api_bellande_extremum_optimization</name>
|
||||
<version>0.0.1</version>
|
||||
<description>Bellande ROS/ROS2 package with a JSON config file for making HTTP requests</description>
|
||||
<author email="ronaldsonbellande@gmail.com">Ronaldson Bellande</author>
|
||||
<maintainer email="ronaldsonbellande@gmail.com">Ronaldson Bellande</maintainer>
|
||||
<license>Apache License 2.0</license>
|
||||
|
||||
|
||||
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>
|
||||
|
||||
<build_depend condition="$ROS_VERSION == 1">roscpp</build_depend>
|
||||
<build_depend condition="$ROS_VERSION == 1">rospy</build_depend>
|
||||
|
||||
<build_export_depend condition="$ROS_VERSION == 1">roscpp</build_export_depend>
|
||||
<build_export_depend condition="$ROS_VERSION == 1">rospy</build_export_depend>
|
||||
|
||||
<exec_depend condition="$ROS_VERSION == 1">roscpp</exec_depend>
|
||||
<exec_depend condition="$ROS_VERSION == 1">rospy</exec_depend>
|
||||
|
||||
|
||||
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>
|
||||
|
||||
<build_depend condition="$ROS_VERSION == 2">rclcpp</build_depend>
|
||||
<build_depend condition="$ROS_VERSION == 2">rclpy</build_depend>
|
||||
|
||||
<build_export_depend condition="$ROS_VERSION == 2">rclcpp</build_export_depend>
|
||||
<build_export_depend condition="$ROS_VERSION == 2">rclpy</build_export_depend>
|
||||
|
||||
<exec_depend condition="$ROS_VERSION == 2">rclcpp</exec_depend>
|
||||
<exec_depend condition="$ROS_VERSION == 2">rclpy</exec_depend>
|
||||
|
||||
|
||||
<export>
|
||||
</export>
|
||||
</package>
|
29
web_api_bellande_extremum_optimization/script/build.sh
Normal file
29
web_api_bellande_extremum_optimization/script/build.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Create and navigate to build directory
|
||||
mkdir -p build && cd build
|
||||
|
||||
# Build package
|
||||
if [ $ROS_VERSION -eq 1 ]; then
|
||||
cmake -DROS_VERSION=1 ..
|
||||
make -j$(nproc)
|
||||
else
|
||||
cmake -DROS_VERSION=2 ..
|
||||
make -j$(nproc)
|
||||
fi
|
||||
|
||||
# Source package setup file
|
||||
source devel/setup.bash
|
||||
|
||||
# Run rosdep
|
||||
rosdep install --from-paths ../src --ignore-src -y
|
||||
|
||||
# Return to package root directory
|
||||
cd ..
|
||||
|
||||
# Run ROS launch file
|
||||
if [ $ROS_VERSION -eq 1 ]; then
|
||||
roslaunch web_api_bellande_step bellande_step_api_2d_launch.launch.py x1:=0 y1:=0 x2:=5 y2:=5 limit:=3
|
||||
else
|
||||
ros2 launch web_api_bellande_step bellande_step_api_2d_launch.launch.py x1:=0 y1:=0 x2:=5 y2:=5 limit:=3
|
||||
fi
|
11
web_api_bellande_extremum_optimization/setup.py
Executable file
11
web_api_bellande_extremum_optimization/setup.py
Executable file
@@ -0,0 +1,11 @@
|
||||
from distutils.core import setup
|
||||
from catkin_pkg.python_setup import generate_distutils_setup
|
||||
|
||||
# fetch values from package.xml
|
||||
setup_args = generate_distutils_setup(
|
||||
scripts=['src/bellande_step_api_2d.py'],
|
||||
packages=['web_api_bellande_step'],
|
||||
package_dir={'': 'src'},
|
||||
)
|
||||
|
||||
setup(**setup_args)
|
61
web_api_bellande_extremum_optimization/src/bellande_extremum_optimization.py
Executable file
61
web_api_bellande_extremum_optimization/src/bellande_extremum_optimization.py
Executable file
@@ -0,0 +1,61 @@
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
|
||||
def main():
|
||||
# Get the absolute path to the config file
|
||||
config_file_path = os.path.join(os.path.dirname(__file__), '../config/configs.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(config_file_path, 'r') as config_file:
|
||||
config = json.load(config_file)
|
||||
url = config['url']
|
||||
endpoint_path = config['endpoint_path']["2d"]
|
||||
|
||||
# Get the parameters from the ROS parameter server
|
||||
x1 = rospy.get_param('x1', 0)
|
||||
y1 = rospy.get_param('y1', 0)
|
||||
x2 = rospy.get_param('x2', 0)
|
||||
y2 = rospy.get_param('y2', 0)
|
||||
limit = rospy.get_param('limit', 3)
|
||||
|
||||
# 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)
|
||||
|
||||
if __name__ == '__main__':
|
||||
ros_version = os.getenv("ROS_VERSION")
|
||||
if ros_version == "1":
|
||||
import rospy
|
||||
elif ros_version == "2":
|
||||
import rclpy
|
||||
|
||||
main()
|
Reference in New Issue
Block a user