Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/carla carma state integration #49

Merged
merged 26 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions carla-carma-integration/carla_carma_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ project(carla_carma_bridge)
find_package(catkin REQUIRED COMPONENTS
autoware_msgs
rospy
cav_srvs
cav_msgs

)

catkin_python_setup()
Expand All @@ -21,6 +23,10 @@ catkin_install_python(PROGRAMS
src/carla_carma_bridge/carla_to_carma_localization
src/carla_carma_bridge/carma_to_carla_ackermann_cmd
src/carla_carma_bridge/carla_to_carma_external_objects
src/carla_carma_bridge/carma_carla_route
src/carla_carma_bridge/carma_carla_plugins
src/carla_carma_bridge/carma_carla_guidance

DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#String: Route to be initialized
selected_route: '/opt/carma/routes/tfhrc_test_route.csv'

# List of String: Required plugins for the platform to be functional
selected_plugins:
- RouteFollowing
- InLaneCruisingPlugin
- StopAndWaitPlugin
- Pure Pursuit
2 changes: 2 additions & 0 deletions carla-carma-integration/carla_carma_bridge/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<exec_depend>autoware_msgs</exec_depend>
<exec_depend>carla_msgs</exec_depend>
<exec_depend>cav_msgs</exec_depend>
<exec_depend>cav_srvs</exec_depend>

<export>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# Copyright (C) 2021 LEIDOS.
#
# 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.

import rospy
from cav_msgs.msg import RouteEvent
from cav_msgs.msg import Plugin

route_selected = False
plugins_activated = False

def check_route_status(route_event_msg):
if route_event_msg.event == 1:
print("Route Selected")
route_selected = True
chengyuan0124 marked this conversation as resolved.
Show resolved Hide resolved

def check_plugin_status(plugin_msg):
if plugin_msg.activated == True:
print("Plugins Activated")
#NOTE: May have to add logic to parse through every individual plugin and determine their status
plugins_activated = True
chengyuan0124 marked this conversation as resolved.
Show resolved Hide resolved

def initialize():
service = rospy.ServiceProxy('/set_active_guidance')
chengyuan0124 marked this conversation as resolved.
Show resolved Hide resolved
route_sub = rospy.Subscriber("/route_event",RouteEvent(), check_route_status)
plugin_sub = rospy.Subscriber("/plugin_discovery", Plugin(), check_plugin_status)
if route_selected == True && plugins_activated == True:
service.call()
else:
rospy.spin()

if __name__ == '__main__':
print("carma_carla_guidance")
initialize()
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# Copyright (C) 2021 LEIDOS.
#
# 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.
#
#
# This file is loosely based on the reference architecture developed by Intel Corporation for Leidos located here
# https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/health_monitor/src/plugin_manager.cpp
#
# That file has the following license and some code snippets from it may be present in this file as well and are under the same license.
#
# Copyright (c) 2018-2019 Intel Corporation
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
#

import rospy
from cav_msgs.msg import Plugin, PluginList, PluginStatus
from cav_srvs.srv import GetRegisteredPlugins

selected_plugins = rospy.get_param('selected_plugins')
activation_srv = rospy.ServiceProxy("/activate_plugin")


#List to contain the registered plugins from the service call in initialize()
plugin_list = PluginList()


#Check if the plugin is included in the list of required plugins
def check_selected_plugins(name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is equivalent to name in selected_plugins if you want to simplify things a bit.

for i in selected_plugins:
if i == name:
return True
else:
return False

def plugin_status_cb(plugin_msg):
print("Received status from: " ++ plugin_msg.name)
requested = check_plugin_registration(plugin_msg)

#If the requested plugin is not registered, print error message
if requested != None:
print("Incoming plugin is not included in list of registered plugins")
elif check_selected_plugins(plugin_msg.name) == True:
plugin_msg.activated = True
activation_srv.call(plugin_msg.name, plugin_msg.activated)


#Search through list of registered plugins. If it exists, return the requested plugin
def check_plugin_registration(plugin):
if plugin in plugin_list.plugins:
return True
else:
return False


def initialize():
registered_plugins_serv = rospy.ServiceProxy('/get_registered_plugins')
plugin_list.plugins = registered_plugins_serv.call()
plugin_sub = rospy.Subscriber('/plugin_discovery',Plugin(), plugin_status_cb)
rospy.spin()
kjrush marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == '__main__':
print("carma_carla_plugins")
initialize()
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env python
# Copyright (C) 2021 LEIDOS.
#
# 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.
"""
Call Services from CARMA:
Service: /guidance/get_available_routes
/guidance/set_active_route

Publish to CARMA :cav_msgs::Route

"""

import rospy
from geometry_msgs.msg import PoseStamped, Pose
from cav_msgs.msg import RouteState
from cav_msgs.msg import Route
from cav_msgs.msg import RouteEvent, GuidanceState
from cav_srvs.srv import GetAvailableRoutes
from cav_srvs.srv import SetActiveRoute

state_pub = rospy.Publisher('/guidance/state', GuidanceState)
selected_route = rospy.get_param('selected_route')

class ErrorStatus:
def __init__(self, value, text):
self.value = value
self.text = text

NO_ERROR = ErrorStatus(0, "NO_ERROR")
NO_ROUTE = ErrorStatus(1, "NO_ROUTE")
ALREADY_FOLLOWING_ROUTE = ErrorStatus(2, "ALREADY_FOLLOWING_ROUTE")
ROUTE_FILE_ERROR = ErrorStatus(3, "ROUTE_FILE_ERROR")
ROUTING_FAILURE = ErrorStatus(4, "ROUTING_FAILURE")
TRANSFORM_ERROR = ErrorStatus(5, "TRANSFORM_ERROR")

#Get the routes to be set after localization
def get_available_routes():
service = rospy.ServiceProxy('/get_available_routes', GetAvailableRoutes)
try:
resp = service.call(0)
available_routes = GetAvailableRoutes()
available_routes.availableRoutes = resp.availableRoutes

except:
print("Invalid: /guidance/get_available_routes failed.")
else:
print("Available Routes acquired")
return available_routes.availableRoutes



def set_route(id):
service = rospy.ServiceProxy('/set_active_route', SetActiveRoute)

try:
#Service Call Request
resp = service(0, id)
if resp.errorStatus != NO_ERROR.value:
errorDescription = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this errorDescription used anywhere? Not sure what all this error handling is intended for, it can probably be simplified to a check for the "NO_ERROR" value and a generic exception or error notice on all other cases. I don't think there's a meaningful way for this node to handle any of these other errors outside of maybe waiting a brief delay and retrying right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this?

if resp.errorStatus == NO_ROUTE.value:
lewisid marked this conversation as resolved.
Show resolved Hide resolved
errorDescription = NO_ROUTE.text

elif resp.errorStatus == ALREADY_FOLLOWING_ROUTE.value:
errorDescription = ALREADY_FOLLOWING_ROUTE.text

elif resp.errorStatus == ROUTE_FILE_ERROR.value:
errorDescription = ROUTE_FILE_ERROR.text

elif resp.errorStatus == ROUTING_FAILURE.value:
errorDescription = ROUTING_FAILURE.text

elif resp.errorStatus == TRANSFORM_ERROR.value:
errorDescription = TRANSFORM_ERROR.text

else:
errorDescription = resp.errorStatus

print(errorDescription)

else:
#Call succeeded: Setting Route
print('call set active route success!')
#Change Guidance from READY to ACTIVE
#set_guidance_active()



except:
print("Fail")




def route_event_callback(event):
route_event = RouteEvent()
route_event.event = event
if route_event.event == 6:
print("ROUTE_GEN_FAILED")

def check_selected_route(available_routes):
if selected_route in available_routes:
kjrush marked this conversation as resolved.
Show resolved Hide resolved
return selected_route

def initialize():
route_event_sub = rospy.Subscriber('/guidance/route_event', RouteEvent,route_event_callback)
available_routes = get_available_routes()

#Ensure that localization is complete before checking route information
localized_sub = rospy.Subscriber('/localization/current_pose', PoseStamped)
if localized_sub:
chengyuan0124 marked this conversation as resolved.
Show resolved Hide resolved
if available_routes == None:
print("No routes available.")
else:
"""Check if the selected route is one of the available routes. If it isn't,then print error statement"""
if check_selected_route(available_routes) == True:
route = selected_route
set_route(route.route_id)

else:
print("Error: Invalid selected route")
rospy.spin()


else:
print("Localization Incomplete")
rospy.spin()


if __name__ == '__main__':
print("carma_carla_route")
initialize()