-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge app_manager_utils to app_manager
- Loading branch information
Showing
89 changed files
with
2,412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(app_notification_saver) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
message_generation | ||
rospy | ||
) | ||
|
||
add_service_files( | ||
FILES SaveAppNotification.srv | ||
) | ||
|
||
catkin_python_setup() | ||
|
||
generate_messages() | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS message_runtime | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
# app_notification_saver | ||
|
||
Plugins and nodes to save notification to json file and pass it to `app_notifier` | ||
|
||
## `app_manager` plugins | ||
|
||
### `app_notification_saver/service_notification_saver`: General notification saver plugin | ||
|
||
This plugin saves notification via service call. | ||
|
||
#### `plugin_args`: Plugin arguments | ||
|
||
`None` | ||
|
||
#### `launch_args`: Plugin launch arguments | ||
|
||
- `json_path` : JSON path | ||
|
||
#### Sample plugin description | ||
|
||
```yaml | ||
plugins: | ||
- name: service_notification_saver | ||
type: app_notification_saver/service_notification_saver | ||
launch_args: | ||
json_path: /tmp/app_notification.json | ||
``` | ||
#### Save app notification | ||
You can save app notification with service call. | ||
```bash | ||
rosservice call /service_notification_saver/save_app_notification "title: 'object recognition' | ||
stamp: | ||
secs: 1627467479 | ||
nsecs: 13279914 | ||
location: 'kitchen' | ||
message: 'Dish is found'" | ||
``` | ||
#### Clear app notification | ||
You can also clear app notification. | ||
```bash | ||
rosservice call /service_notification_saver/clear_app_notification "{}" | ||
``` | ||
### `app_notification_saver/smach_notification_saver`: SMACH notification saver plugin | ||
|
||
This plugin saves notification via service call. | ||
|
||
#### `plugin_args`: Plugin arguments | ||
|
||
`None` | ||
|
||
#### `launch_args`: Plugin launch arguments | ||
|
||
- `json_path` : JSON path | ||
- `smach_status_topic`: SMACH status topic name | ||
|
||
#### Sample plugin description | ||
|
||
```yaml | ||
plugins: | ||
- name: smach_notification_saver | ||
type: app_notification_saver/smach_notification_saver | ||
launch_args: | ||
json_path: /tmp/app_notification.json | ||
smach_status_topic: /server_name/smach/container_status | ||
``` | ||
|
||
## Nodes | ||
|
||
### `service_notification_saver_node.py`: Node for general notification saver | ||
|
||
Save notification node via service call. | ||
|
||
#### Services | ||
|
||
- `~save_app_notification` (`app_notification_saver/SaveAppNotification`) | ||
|
||
Service to save app notification to JSON. | ||
|
||
- `~clear_app_notification` (`std_srvs/Empty`) | ||
|
||
Service to clear app notification in JSON. | ||
|
||
#### Parameters | ||
|
||
- `~json_path` (`String`, default: `/tmp/app_notification.json`) | ||
|
||
Path to json file which contains app notification | ||
|
||
#### Sample | ||
|
||
##### Launch service_notification_saver node | ||
|
||
```bash | ||
roslaunch app_notification_saver service_notification_saver.launch | ||
``` | ||
|
||
##### Save app notification | ||
|
||
You can save app notification with service call. | ||
|
||
```bash | ||
rosservice call /service_notification_saver/save_app_notification "title: 'object recognition' | ||
stamp: | ||
secs: 1627467479 | ||
nsecs: 13279914 | ||
location: 'kitchen' | ||
message: 'Dish is found'" | ||
``` | ||
|
||
##### Clear app notification | ||
|
||
You can also clear app notification. | ||
|
||
```bash | ||
rosservice call /service_notification_saver/clear_app_notification "{}" | ||
``` | ||
|
||
##### Check output JSON | ||
|
||
The sample output of the json file is like below: | ||
|
||
```json | ||
{ | ||
"object recognition": [ | ||
{ | ||
"date": "2021-07-28T19:17:59", | ||
"message": "Dish is found", | ||
"location": "kitchen" | ||
}, | ||
{ | ||
"date": "2021-07-28T19:18:09", | ||
"message": "Cup is found", | ||
"location": "kitchen" | ||
} | ||
], | ||
"navigation failure": [ | ||
{ | ||
"date": "2021-07-28T19:18:29", | ||
"message": "Stucked in front of the chair", | ||
"location": "living room" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### `smach_notification_saver_node.py`: Node for SMACH notification saver | ||
|
||
Save notification of smach state. | ||
|
||
#### Subscribe topics | ||
|
||
- `~smach/container_status` (`smach_msgs/SmachContainerStatus`, default: `/server_name/smach/container_status`) | ||
|
||
Smach status topic | ||
|
||
#### Parameters | ||
|
||
- `~json_path` (`String`, default: `/tmp/app_notification.json`) | ||
|
||
Path to json file which contains app notification | ||
|
||
#### Sample | ||
|
||
##### Launch smach_notification_saver node | ||
|
||
```bash | ||
# Launch only smach_notification_saver node | ||
roslaunch app_notification_saver smach_notification_saver.launch | ||
# Sample | ||
# Launch smach_notification_saver node and rosbag | ||
roslaunch app_notification_saver sample_smach_notification_saver.launch --screen | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- name: app_notification_saver/service_notification_saver | ||
launch: app_notification_saver/service_notification_saver.launch | ||
module: null | ||
- name: app_notification_saver/smach_notification_saver | ||
launch: app_notification_saver/smach_notification_saver.launch | ||
module: null |
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
app_notification_saver/launch/service_notification_saver.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<launch> | ||
<!-- start: arguments --> | ||
<arg name="json_path" default="/tmp/app_notification.json" /> | ||
<!-- end: arguments --> | ||
|
||
<node name="service_notification_saver" pkg="app_notification_saver" | ||
type="service_notification_saver_node.py"> | ||
<rosparam subst_value="true"> | ||
json_path: $(arg json_path) | ||
</rosparam> | ||
</node> | ||
</launch> |
14 changes: 14 additions & 0 deletions
14
app_notification_saver/launch/smach_notification_saver.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<launch> | ||
<!-- start: arguments --> | ||
<arg name="json_path" default="/tmp/app_notification.json" /> | ||
<arg name="smach_status_topic" default="/server_name/smach/container_status" /> | ||
<!-- end: arguments --> | ||
|
||
<node name="smach_notification_saver" pkg="app_notification_saver" | ||
type="smach_notification_saver_node.py" > | ||
<remap from="~smach/container_status" to="$(arg smach_status_topic)" /> | ||
<rosparam subst_value="true"> | ||
json_path: $(arg json_path) | ||
</rosparam> | ||
</node> | ||
</launch> |
11 changes: 11 additions & 0 deletions
11
app_notification_saver/node_scripts/service_notification_saver_node.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
|
||
from app_notification_saver import ServiceNotificationSaver | ||
|
||
|
||
if __name__ == '__main__': | ||
rospy.init_node('service_notification_saver_node') | ||
ServiceNotificationSaver() | ||
rospy.spin() |
10 changes: 10 additions & 0 deletions
10
app_notification_saver/node_scripts/smach_notification_saver_node.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
|
||
from app_notification_saver import SmachNotificationSaver | ||
|
||
if __name__ == '__main__': | ||
rospy.init_node('smach_notification_saver_node') | ||
SmachNotificationSaver() | ||
rospy.spin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0"?> | ||
<package format="3"> | ||
<name>app_notification_saver</name> | ||
<version>1.3.0</version> | ||
<description>The app_notification_saver package</description> | ||
|
||
<maintainer email="[email protected]">Shingo Kitagawa</maintainer> | ||
<author email="[email protected]">Naoya Yamaguchi</author> | ||
<license>BSD</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<buildtool_depend condition="$ROS_PYTHON_VERSION == 2">python-setuptools</buildtool_depend> | ||
<buildtool_depend condition="$ROS_PYTHON_VERSION == 3">python3-setuptools</buildtool_depend> | ||
|
||
<build_depend>message_generation</build_depend> | ||
<exec_depend>app_manager</exec_depend> | ||
<exec_depend>message_runtime</exec_depend> | ||
<exec_depend>rospy</exec_depend> | ||
<exec_depend>smach_msgs</exec_depend> | ||
|
||
<export> | ||
<app_manager plugin="${prefix}/app_notification_saver_plugin.yaml" /> | ||
</export> | ||
</package> |
9 changes: 9 additions & 0 deletions
9
app_notification_saver/sample/sample_smach_notification_saver.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<launch> | ||
<node name="rosbag_play" pkg="rosbag" type="play" | ||
args="$(find app_notification_saver)/data/smach.bag --clock" | ||
output="screen" required="true" /> | ||
|
||
<include file="$(find app_notification_saver)/launch/smach_notification_saver.launch" > | ||
<arg name="smach_status_topic" value="/server_name/smach/container_status" /> | ||
</include> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from catkin_pkg.python_setup import generate_distutils_setup | ||
from setuptools import find_packages | ||
from setuptools import setup | ||
|
||
|
||
d = generate_distutils_setup( | ||
packages=find_packages('src'), | ||
package_dir={'': 'src'}, | ||
) | ||
|
||
setup(**d) |
3 changes: 3 additions & 0 deletions
3
app_notification_saver/src/app_notification_saver/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from app_notification_saver.app_notification_saver_base import AppNotificationSaver # NOQA | ||
from app_notification_saver.service_notification_saver import ServiceNotificationSaver # NOQA | ||
from app_notification_saver.smach_notification_saver import SmachNotificationSaver # NOQA |
43 changes: 43 additions & 0 deletions
43
app_notification_saver/src/app_notification_saver/app_notification_saver_base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import datetime | ||
import json | ||
import os | ||
import rospy | ||
|
||
|
||
class AppNotificationSaver(object): | ||
def __init__(self): | ||
self.json_path = rospy.get_param( | ||
'~json_path', '/tmp/app_notification.json') | ||
|
||
def save_app_notification(self, title, stamp, location, message): | ||
""" | ||
Save app notification to json file. | ||
Args: | ||
title (str) : Notification title (e.g. object detection, navigation faliure ...) # NOQA | ||
stamp (float) : UNIX time when the event occurred | ||
location (str): The location where the event occurred | ||
message (str) : Notification message | ||
Returns: | ||
Result of whether the json was saved. (bool) | ||
""" | ||
# Load notification json | ||
if os.path.exists(self.json_path): | ||
with open(self.json_path, 'r') as j: | ||
notification = json.load(j) | ||
else: | ||
notification = {} | ||
# Append notification | ||
stamp = datetime.datetime.fromtimestamp(stamp) | ||
new_notification = {'date': stamp.isoformat(), | ||
'location': location, | ||
'message': message} | ||
if title in notification: | ||
notification[title].append(new_notification) | ||
else: | ||
notification[title] = [new_notification] | ||
# Dump json | ||
with open(self.json_path, 'w') as j: | ||
json.dump(notification, j, indent=4) | ||
rospy.loginfo(json.dumps(notification, indent=4)) |
33 changes: 33 additions & 0 deletions
33
app_notification_saver/src/app_notification_saver/service_notification_saver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import rospy | ||
|
||
from app_notification_saver import AppNotificationSaver | ||
|
||
from app_notification_saver.srv import SaveAppNotification | ||
from app_notification_saver.srv import SaveAppNotificationResponse | ||
from std_srvs.srv import Empty | ||
from std_srvs.srv import EmptyResponse | ||
|
||
|
||
class ServiceNotificationSaver(AppNotificationSaver): | ||
def __init__(self): | ||
super(ServiceNotificationSaver, self).__init__() | ||
rospy.Service( | ||
'~save_app_notification', | ||
SaveAppNotification, | ||
self.save_service_notification_cb) | ||
rospy.Service( | ||
'~clear_app_notification', | ||
Empty, | ||
self.clear_app_notification_cb) | ||
|
||
def save_service_notification_cb(self, req): | ||
self.save_app_notification( | ||
req.title, float(req.stamp.secs), req.location, req.message) | ||
return SaveAppNotificationResponse(True) | ||
|
||
def clear_app_notification_cb(self, req): | ||
if os.path.exists(self.json_path): | ||
os.remove(self.json_path) | ||
rospy.loginfo('Remove file {}'.format(self.json_path)) | ||
return EmptyResponse() |
Oops, something went wrong.