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

F adding component to watchdog #69

Merged
merged 34 commits into from Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7d20573
initial commit
mikramarc Jun 18, 2019
604d319
moved gui stuff to watchdog pkg
mikramarc Jun 18, 2019
61333f4
getting there
mikramarc Jun 20, 2019
d70f8a8
cleaned up javascript
mikramarc Jun 20, 2019
35b9c66
adding launch files
mikramarc Jun 20, 2019
f49cee4
initial cleanup
mikramarc Jun 20, 2019
6f65393
fixed a bug
mikramarc Jun 21, 2019
a84a18f
more cleanup
mikramarc Jun 21, 2019
e038391
more cleanup
mikramarc Jun 21, 2019
50692d8
adding readme
mikramarc Jun 21, 2019
256fd58
fixing lint
mikramarc Jun 21, 2019
fa1fc57
Merge branch 'kinetic-devel' of github.com:shadow-robot/common_resour…
mikramarc Jun 24, 2019
195e1dd
lint
mikramarc Jun 24, 2019
3708117
lint
mikramarc Jun 24, 2019
30c4f3c
please
mikramarc Jun 24, 2019
86ac71f
minor change
mikramarc Jun 24, 2019
4a01136
minor update
mikramarc Jun 24, 2019
0735c03
added figure
mikramarc Jun 24, 2019
c30e0a3
adding additional explanation
mikramarc Jun 24, 2019
590f509
handling component
mikramarc Jun 27, 2019
d74fadc
cleaning up
mikramarc Jun 27, 2019
ee1f052
minor changes
mikramarc Jun 28, 2019
5e5182e
renaming class
mikramarc Jun 28, 2019
4f13e4f
adding component to show in gui
mikramarc Jun 28, 2019
838ee8d
streching box depending on contents
mikramarc Jun 28, 2019
8f0a531
updating readme
mikramarc Jun 28, 2019
398c640
lint
mikramarc Jun 28, 2019
5d28758
Merge branch 'kinetic-devel' of github.com:shadow-robot/common_resour…
mikramarc Jun 28, 2019
04258d2
finishing the watchdog test
mikramarc Jul 1, 2019
b3e0e46
minor change
mikramarc Jul 1, 2019
f189169
fixing lint
mikramarc Jul 1, 2019
5f39fd7
Merge branch 'kinetic-devel' of github.com:shadow-robot/common_resour…
mikramarc Jul 1, 2019
907560e
fixing according to the review
mikramarc Jul 8, 2019
c4f16fa
fixing a typo
mikramarc Jul 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 0 additions & 59 deletions sr_utilities_common/README.md
Expand Up @@ -27,62 +27,3 @@ if __name__ == '__main__':
```

The above code will be executing an infinite loop until shutdown for the node is initiated. Then, before the node dies, the `clean_up` method will be executed.

## Watchdog
A watchdog class that continuously runs specified check methods and informs the user about any undesired behaviours.

<p align="center">
<img src="doc/watchdog.png">
</p>

An example of how to properly use the class can be seen in the code snipper below:
```python
#!/usr/bin/python

import rospy
from sr_utilities_common.shutdown_handler import ShutdownHandler
from sr_utilities_common.watchdog import SrWatchdog

class TestChecksClass(object):
def __init__(self):
self.tmp = [0, 0, 0]

def mock_check_robot_clear_from_collision(self):
rospy.sleep(4)
if self.tmp[0] != 1:
self.tmp[0] = 1
return False
else:
self.tmp[0] = 0
return True

def mock_check_if_arm_running(self):
rospy.sleep(5)
if self.tmp[1] != 0:
self.tmp[1] = 0
return (False, "Something went wrong!")
else:
self.tmp[1] = 1
return True


if __name__ == '__main__':
rospy.init_node('mock_sr_teleop_watchdog')

test_class = TestChecksClass()
error_checks_list = ['mock_check_if_arm_running']
warning_checks_list = ['mock_check_robot_clear_from_collision']

teleop_watchdog = SrWatchdog(test_class, error_checks_list, warning_checks_list)
shutdown_handler = ShutdownHandler(teleop_watchdog, 'clean_up()')
teleop_watchdog.run()
rospy.spin()
```

All the check methods are defined in a separate class. There are two types of checks supported. Error checks, which will change general status to `error` and throw an error message, and warning checks, which do not affect the reported status but inform the user that something has happened. In order to classify a check as error or warning check, their method name needs to be put in a proper list that is further passed to the `SrWatchdog` class constructor, together with the checks class object.

The check methods are required to return either `True` (for passed check) or `False` (for failed check) values. Alternatively, in case of failure, error checks can return a tuple of `(False, <error message>)` where `<error message>` is additional, user-defined error message.

In the code snippet above, a `ShutdownHandler` is defined as well in order to clean up console display changes performed by the watchdog class. This step is desired, but not necessary.

It is recommended to run the watchdog in a separate xterm window, as used in this [launch file](./launch/mock_watchdog.launch). This launch file can also be used as a reference to how the watchdog class works.
232 changes: 0 additions & 232 deletions sr_utilities_common/scripts/sr_utilities_common/watchdog.py

This file was deleted.