latest pushes
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# 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_adaptive_continuious_controller)
|
||||
|
||||
# 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 for both ROS 1
|
||||
if($ENV{ROS_VERSION} EQUAL 1)
|
||||
catkin_install_python(
|
||||
PROGRAMS
|
||||
src/bellande_controller.py
|
||||
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Install Python scripts, configuration files, and launch files
|
||||
if($ENV{ROS_VERSION} EQUAL "1")
|
||||
install(PROGRAMS src/bellande_controller.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_controller.py DESTINATION lib/${PROJECT_NAME})
|
||||
install(DIRECTORY config/ DESTINATION share/${PROJECT_NAME}/config)
|
||||
install(DIRECTORY launch/ DESTINATION share/${PROJECT_NAME}/launch)
|
||||
endif()
|
@@ -0,0 +1,3 @@
|
||||
# Bellande Search Path Web ROS/ROS2 API Intergration
|
||||
|
||||
[Bellande Search Path](https://github.com/RonaldsonBellande/bellande_robots_step)
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"license": [
|
||||
"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/>.",
|
||||
"GNU General Public License v3.0 or later"
|
||||
],
|
||||
"url": "https://bellande-robotics-sensors-research-innovation-center.org",
|
||||
"endpoint_path": {
|
||||
"bellande_controller": "/api/Bellande_Adaptive_Continuious_Controller/bellande_adaptive_continuious_controller"
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
# 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/>.
|
||||
|
||||
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 command
|
||||
roslaunch_command = ["roslaunch", "web_api_bellande_adaptive_continuious_controller", "bellande_controller.launch"] + args
|
||||
# Execute the launch command
|
||||
subprocess.call(roslaunch_command)
|
||||
|
||||
def ros2_launch_description():
|
||||
# Declare launch arguments
|
||||
gains_arg = DeclareLaunchArgument('gains', default_value='[1.0, 0.1, 0.05]')
|
||||
name_arg = DeclareLaunchArgument('name', default_value='BellandeController')
|
||||
output_limits_arg = DeclareLaunchArgument('output_limits', default_value='[-1000.0, 1000.0]')
|
||||
|
||||
# Create a list to hold all nodes to be launched
|
||||
nodes_to_launch = []
|
||||
|
||||
# ROS2 specific configurations
|
||||
ros_launch_arguments = [
|
||||
gains_arg, name_arg, output_limits_arg,
|
||||
]
|
||||
|
||||
nodes_to_launch.append(Node(
|
||||
package='web_api_bellande_adaptive_continuious_controller',
|
||||
executable='bellande_controller.py',
|
||||
name='bellande_controller_node',
|
||||
output='screen',
|
||||
parameters=[
|
||||
{'gains': LaunchConfiguration('gains')},
|
||||
{'name': LaunchConfiguration('name')},
|
||||
{'output_limits': LaunchConfiguration('output_limits')},
|
||||
],
|
||||
))
|
||||
|
||||
# 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
|
||||
|
||||
T
|
||||
is 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/>.
|
||||
-->
|
||||
|
||||
<launch>
|
||||
<!-- Arguments -->
|
||||
<arg name="gains" default="[1.0, 0.1, 0.05]"/>
|
||||
<arg name="name" default="BellandeController"/>
|
||||
<arg name="output_limits" default="[-1000.0, 1000.0]"/>
|
||||
|
||||
<!-- Launch the BellandeController node -->
|
||||
<node name="bellande_controller_node" pkg="web_api_bellande_adaptive_continuious_controller" type="bellande_controller.py" output="screen">
|
||||
<param name="gains" value="$(arg gains)"/>
|
||||
<param name="name" value="$(arg name)"/>
|
||||
<param name="output_limits" value="$(arg output_limits)"/>
|
||||
</node>
|
||||
</launch>
|
54
web_api_bellande_adaptive_continuious_controller/package.xml
Normal file
54
web_api_bellande_adaptive_continuious_controller/package.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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_adaptive_continuious_controller</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>
|
26
web_api_bellande_adaptive_continuious_controller/setup.py
Executable file
26
web_api_bellande_adaptive_continuious_controller/setup.py
Executable file
@@ -0,0 +1,26 @@
|
||||
# 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/>.
|
||||
|
||||
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_controller.py'],
|
||||
packages=['web_api_bellande_adaptive_continuious_controller'],
|
||||
package_dir={'': 'src'},
|
||||
)
|
||||
|
||||
setup(**setup_args)
|
100
web_api_bellande_adaptive_continuious_controller/src/bellande_controller.py
Executable file
100
web_api_bellande_adaptive_continuious_controller/src/bellande_controller.py
Executable file
@@ -0,0 +1,100 @@
|
||||
# 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/>.
|
||||
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
from std_msgs.msg import Float64
|
||||
|
||||
def bellande_controller(setpoint, current_value, kp, ki, kd):
|
||||
payload = {
|
||||
"setpoint": setpoint,
|
||||
"current_value": current_value,
|
||||
"kp": kp,
|
||||
"ki": ki,
|
||||
"kd": kd
|
||||
}
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_access_key}"
|
||||
}
|
||||
response = requests.post(api_url, json=payload, headers=headers)
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
return result['control_output']
|
||||
else:
|
||||
print(f"Error: {response.status_code} - {response.text}")
|
||||
return None
|
||||
|
||||
def control_callback(msg):
|
||||
setpoint = rospy.get_param('setpoint', 0)
|
||||
kp = rospy.get_param('kp', 1.0)
|
||||
ki = rospy.get_param('ki', 0.1)
|
||||
kd = rospy.get_param('kd', 0.05)
|
||||
|
||||
control_output = bellande_controller(setpoint, msg.data, kp, ki, kd)
|
||||
if control_output is not None:
|
||||
output_msg = Float64()
|
||||
output_msg.data = control_output
|
||||
pub.publish(output_msg)
|
||||
|
||||
def main():
|
||||
global api_url, api_access_key, pub
|
||||
config_file_path = os.path.join(os.path.dirname(__file__), '../config/configs.json')
|
||||
|
||||
if not os.path.exists(config_file_path):
|
||||
print("Config file not found:", config_file_path)
|
||||
return
|
||||
|
||||
with open(config_file_path, 'r') as config_file:
|
||||
config = json.load(config_file)
|
||||
url = config['url']
|
||||
endpoint_path = config['endpoint_path']["bellande_controller"]
|
||||
api_access_key = config["Bellande_Framework_Access_Key"]
|
||||
|
||||
# Initialize ROS node
|
||||
if ros_version == "1":
|
||||
rospy.init_node('bellande_controller_node', anonymous=True)
|
||||
pub = rospy.Publisher('control_output', Float64, queue_size=10)
|
||||
sub = rospy.Subscriber('current_value', Float64, control_callback)
|
||||
elif ros_version == "2":
|
||||
rclpy.init()
|
||||
node = rclpy.create_node('bellande_controller_node')
|
||||
pub = node.create_publisher(Float64, 'control_output', 10)
|
||||
sub = node.create_subscription(Float64, 'current_value', control_callback, 10)
|
||||
|
||||
api_url = f"{url}{endpoint_path}"
|
||||
|
||||
try:
|
||||
print("BellandeController node is running. Ctrl+C to exit.")
|
||||
if ros_version == "1":
|
||||
rospy.spin()
|
||||
elif ros_version == "2":
|
||||
rclpy.spin(node)
|
||||
except KeyboardInterrupt:
|
||||
print("Shutting down BellandeController node.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
finally:
|
||||
if ros_version == "2":
|
||||
node.destroy_node()
|
||||
rclpy.shutdown()
|
||||
|
||||
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