latest pushes
This commit is contained in:
parent
97bb453ebf
commit
9a468a116c
@ -23,30 +23,26 @@ from launch.substitutions import LaunchConfiguration
|
|||||||
|
|
||||||
def ros1_launch_description():
|
def ros1_launch_description():
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
roslaunch_command = ["roslaunch", "bellande_control_system", "bellande_control_system.launch"] + args
|
roslaunch_command = ["roslaunch", "ros_web_api_bellande_adaptive_continuious_control_system", "bellande_control_system.launch"] + args
|
||||||
subprocess.call(roslaunch_command)
|
subprocess.call(roslaunch_command)
|
||||||
|
|
||||||
def ros2_launch_description():
|
def ros2_launch_description():
|
||||||
initial_state_arg = DeclareLaunchArgument('initial_state', default_value='idle')
|
initial_state_arg = DeclareLaunchArgument('initial_state', default_value='idle')
|
||||||
name_arg = DeclareLaunchArgument('name', default_value='BellandeControlSystem')
|
name_arg = DeclareLaunchArgument('name', default_value='BellandeControlSystem')
|
||||||
connectivity_passcode_arg = DeclareLaunchArgument('connectivity_passcode', default_value='default_passcode')
|
|
||||||
bellande_framework_access_key_arg = DeclareLaunchArgument('bellande_framework_access_key', default_value='bellande_web_api_opensource')
|
|
||||||
|
|
||||||
nodes_to_launch = []
|
nodes_to_launch = []
|
||||||
ros_launch_arguments = [
|
ros_launch_arguments = [
|
||||||
initial_state_arg, name_arg, connectivity_passcode_arg, bellande_framework_access_key_arg,
|
initial_state_arg, name_arg,
|
||||||
]
|
]
|
||||||
|
|
||||||
nodes_to_launch.append(Node(
|
nodes_to_launch.append(Node(
|
||||||
package='bellande_control_system',
|
package='ros_web_api_bellande_adaptive_continuious_control_system',
|
||||||
executable='bellande_control_system.py',
|
executable='bellande_control_system.py',
|
||||||
name='bellande_control_system_node',
|
name='bellande_control_system_node',
|
||||||
output='screen',
|
output='screen',
|
||||||
parameters=[
|
parameters=[
|
||||||
{'initial_state': LaunchConfiguration('initial_state')},
|
{'initial_state': LaunchConfiguration('initial_state')},
|
||||||
{'name': LaunchConfiguration('name')},
|
{'name': LaunchConfiguration('name')},
|
||||||
{'connectivity_passcode': LaunchConfiguration('connectivity_passcode')},
|
|
||||||
{'bellande_framework_access_key': LaunchConfiguration('bellande_framework_access_key')},
|
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -18,14 +18,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
<!-- Arguments -->
|
<!-- Arguments -->
|
||||||
<arg name="initial_state" default="idle"/>
|
<arg name="initial_state" default="idle"/>
|
||||||
<arg name="name" default="BellandeControlSystem"/>
|
<arg name="name" default="BellandeControlSystem"/>
|
||||||
<arg name="connectivity_passcode" default="default_passcode"/>
|
|
||||||
<arg name="bellande_framework_access_key" default="bellande_web_api_opensource"/>
|
|
||||||
|
|
||||||
<!-- Launch the BellandeControlSystem node -->
|
<!-- Launch the BellandeControlSystem node -->
|
||||||
<node name="bellande_control_system_node" pkg="bellande_control_system" type="bellande_control_system.py" output="screen">
|
<node name="bellande_control_system_node" pkg="bellande_control_system" type="bellande_control_system.py" output="screen">
|
||||||
<param name="initial_state" value="$(arg initial_state)"/>
|
<param name="initial_state" value="$(arg initial_state)"/>
|
||||||
<param name="name" value="$(arg name)"/>
|
<param name="name" value="$(arg name)"/>
|
||||||
<param name="connectivity_passcode" value="$(arg connectivity_passcode)"/>
|
|
||||||
<param name="bellande_framework_access_key" value="$(arg bellande_framework_access_key)"/>
|
|
||||||
</node>
|
</node>
|
||||||
</launch>
|
</launch>
|
||||||
|
@ -18,15 +18,14 @@ import os
|
|||||||
import requests
|
import requests
|
||||||
from std_msgs.msg import String
|
from std_msgs.msg import String
|
||||||
|
|
||||||
def bellande_control_system(state, action, parameters, connectivity_passcode):
|
def bellande_control_system(state, action, parameters):
|
||||||
payload = {
|
payload = {
|
||||||
"state": state,
|
"state": state,
|
||||||
"action": action,
|
"action": action,
|
||||||
"parameters": parameters,
|
"parameters": parameters
|
||||||
"connectivity_passcode": connectivity_passcode
|
|
||||||
}
|
}
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {Bellande_Framework_Access_Key}",
|
"Authorization": f"Bearer {api_access_key}",
|
||||||
"X-Connectivity-Passcode": connectivity_passcode
|
"X-Connectivity-Passcode": connectivity_passcode
|
||||||
}
|
}
|
||||||
response = requests.post(api_url, json=payload, headers=headers)
|
response = requests.post(api_url, json=payload, headers=headers)
|
||||||
@ -39,25 +38,23 @@ def bellande_control_system(state, action, parameters, connectivity_passcode):
|
|||||||
|
|
||||||
def control_callback(msg):
|
def control_callback(msg):
|
||||||
data = json.loads(msg.data)
|
data = json.loads(msg.data)
|
||||||
connectivity_passcode = data['connectivity_passcode']
|
current_state = rospy.get_param('current_state', 'idle')
|
||||||
current_state = rospy.get_param(f'current_state_{connectivity_passcode}', 'idle')
|
|
||||||
action = data['action']
|
action = data['action']
|
||||||
parameters = data['parameters']
|
parameters = data['parameters']
|
||||||
|
|
||||||
output, next_state = bellande_control_system(current_state, action, parameters, connectivity_passcode)
|
output, next_state = bellande_control_system(current_state, action, parameters)
|
||||||
if output is not None:
|
if output is not None:
|
||||||
output_msg = String()
|
output_msg = String()
|
||||||
output_msg.data = json.dumps({
|
output_msg.data = json.dumps({
|
||||||
"output": output,
|
"output": output,
|
||||||
"next_state": next_state,
|
"next_state": next_state
|
||||||
"connectivity_passcode": connectivity_passcode
|
|
||||||
})
|
})
|
||||||
pub.publish(output_msg)
|
pub.publish(output_msg)
|
||||||
if next_state:
|
if next_state:
|
||||||
rospy.set_param(f'current_state_{connectivity_passcode}', next_state)
|
rospy.set_param('current_state', next_state)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global api_url, Bellande_Framework_Access_Key, pub
|
global api_url, api_access_key, connectivity_passcode, pub
|
||||||
config_file_path = os.path.join(os.path.dirname(__file__), '../config/configs.json')
|
config_file_path = os.path.join(os.path.dirname(__file__), '../config/configs.json')
|
||||||
|
|
||||||
if not os.path.exists(config_file_path):
|
if not os.path.exists(config_file_path):
|
||||||
@ -68,7 +65,8 @@ def main():
|
|||||||
config = json.load(config_file)
|
config = json.load(config_file)
|
||||||
url = config['url']
|
url = config['url']
|
||||||
endpoint_path = config['endpoint_path']["bellande_control_system_base"]
|
endpoint_path = config['endpoint_path']["bellande_control_system_base"]
|
||||||
Bellande_Framework_Access_Key = config["Bellande_Framework_Access_Key"]
|
connectivity_passcode = config["connectivity_passcode"]
|
||||||
|
api_access_key = config["Bellande_Framework_Access_Key"]
|
||||||
|
|
||||||
# Initialize ROS node
|
# Initialize ROS node
|
||||||
if ros_version == "1":
|
if ros_version == "1":
|
||||||
|
Loading…
Reference in New Issue
Block a user