forked from francescodelduchetto/sentor
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from adambinch/sentor_devel
Custom Lambda Expressions.
- Loading branch information
Showing
4 changed files
with
30 additions
and
6 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
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 | ||
""" | ||
Created on Fri Nov 20 11:35:22 2020 | ||
@author: Adam Binch ([email protected]) | ||
""" | ||
######################################################################################################### | ||
def CustomLambda(msg): | ||
return msg.data == True | ||
######################################################################################################### |
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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
#!/usr/bin/env python | ||
""" | ||
@author: Francesco Del Duchetto ([email protected]) | ||
@author: Adam Binch ([email protected]) | ||
""" | ||
##################################################################################### | ||
from __future__ import division | ||
import rospy, math, numpy | ||
# imported the package `math` so that it can be used in the lambda expressions | ||
# imported the packages math and numpy so that they can be used in the lambda expressions | ||
|
||
class ROSTopicFilter(object): | ||
|
||
def __init__(self, topic_name, lambda_fn_str, config): | ||
self.topic_name = topic_name | ||
self.lambda_fn_str = lambda_fn_str | ||
self.config = config | ||
|
||
self.lambda_fn = None | ||
try: | ||
self.lambda_fn = eval(self.lambda_fn_str) | ||
if config["file"] is not None and config["package"] is not None: | ||
exec("from {}.{} import {} as lambda_fn".format(config["package"], config["file"], self.lambda_fn_str)) | ||
self.lambda_fn = lambda_fn | ||
else: | ||
self.lambda_fn = eval(self.lambda_fn_str) | ||
except Exception as e: | ||
rospy.logerr("Error evaluating lambda function %s : %s" % (self.lambda_fn_str, e)) | ||
|
||
|
@@ -73,4 +78,4 @@ def register_satisfied_cb(self, func): | |
def register_unsatisfied_cb(self, func): | ||
|
||
self.unsat_callbacks.append(func) | ||
##################################################################################### | ||
##################################################################################### |
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