generated from chicagoedt/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.py
69 lines (48 loc) · 2.07 KB
/
filter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from robot_interfaces.msg import LinActPos
class FilterNode(Node):
def __init__(self):
super().__init__("filter_lift")
self.declare_param()
self.get_param()
self.subscriber_feedback = self.create_subscription(LinActPos,self.sub_topic,self.get_feedback,10)
self.publisher_feedback = self.create_publisher(LinActPos,self.pub_topic,10)
self.feedback = [0.0,0.0]
self.prev = [0.0, 0.0]
self.count = 0
self.get_logger().info("filter node activated")
def declare_param(self):
self.declare_parameter('subscriber_topic','lift_feedback')
self.declare_parameter('publisher_topic','lift_feedback_filt')
self.declare_parameter('percent_taken',0.9)
def get_param(self):
self.sub_topic = self.get_parameter('subscriber_topic').get_parameter_value().string_value
self.pub_topic = self.get_parameter('publisher_topic').get_parameter_value().string_value
self.perc = self.get_parameter('percent_taken').get_parameter_value().double_value
def get_feedback(self,msg):
self.feedback = msg.rl_lin_act
if self.count == 0:
self.prev = self.feedback
self.count = 1
else:
for i in range(2):
self.feedback[i] = int(self.perc*self.prev[i]+(1-self.perc)*self.feedback[i])
if self.feedback[i]>1024:
self.feedback[i] = 1024
if self.sub_topic == 'tilt_feedback':
#self.feedback[0] = self.feedback[1]
#self.feedback[0] = int(-self.feedback[0]+866)
self.feedback[1] = self.feedback[0]
feedback = LinActPos()
feedback.rl_lin_act = self.feedback
self.publisher_feedback.publish(feedback)
self.prev = self.feedback
def main(args=None):
rclpy.init(args=args)
node = FilterNode()
rclpy.spin(node)
rclpy.shutdown()
if __name__== "__main__":
main()