drc_2015_environment.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 import sys
4 from mm2client import *
5 import setfilters
6 from periodic import *
7 from dynamic_reconfigure.server import Server as DynamicReconfigureServer
8 from mini_maxwell.cfg import DRCEnvironmentConfig as ConfigType
9 from threading import Lock
10 from random import randint
11 from std_msgs.msg import Bool, Time
12 # constant variable for readability
13 LANA_to_LANB = True
14 LANB_to_LANA = False
15 
17  def __init__(self):
18  self.mm2name = rospy.get_param('~ip', '133.11.216.47')
19  self.low_speed_name = "drc_low_speed"
20  self.high_speed_name = "drc_high_speed"
21  self.bands = Bands()
22  self.lock = Lock()
25 
26  self.pub_is_disabled = rospy.Publisher("~is_disabled", Bool)
27  self.pub_is_blackout = rospy.Publisher("~is_blackout", Bool)
28  self.pub_next_whiteout_time = rospy.Publisher("~next_whiteout_time", Time)
29  # low speed -> 1
30  # high speed -> 2
32  low_speed_filter = setfilters.FiltSetting(self.low_speed_name,
33  self.LOW_SPEED_BAND_NUM)
34 
35  high_speed_filter = setfilters.FiltSetting(self.high_speed_name,
37  self.filters = [low_speed_filter, high_speed_filter]
38  self.server = DynamicReconfigureServer(ConfigType, self.reconfigure)
39  self.blackoutp = False
40  self.next_blackout = rospy.Time.now()
41  self.next_whiteout = rospy.Time.now()
42  self.blackout()
43  self.timer = rospy.Timer(rospy.Duration(0.1), self.publishStatus)
44  self.timer = rospy.Timer(rospy.Duration(1.0), self.updateBlackout)
45  rospy.spin()
46  def publishStatus(self, event):
47  with self.lock:
48  self.pub_is_disabled.publish(Bool(data=self.disable_network_limitation))
49  self.pub_is_blackout.publish(Bool(data=self.blackoutp))
50  self.pub_next_whiteout_time.publish(Time(data=self.next_whiteout))
51  def updateBlackout(self, event):
52  with self.lock:
53  if not self.disable_network_limitation:
54  now = rospy.Time.now()
55  if not self.blackoutp:
56  if (self.next_blackout - now).to_sec() < 0:
57  self.blackout()
58  else:
59  if (self.next_whiteout - now).to_sec() < 0:
60  self.whiteout()
61  def reconfigure(self, config, level):
62  with self.lock:
63  self.disable_network_limitation = config["disable_network_limitation"]
64 
65  self.low_speed_link_bandwidth = config["low_speed_link_bandwidth"]
66 
67  self.high_speed_link_bandwidth = config["high_speed_link_bandwidth"]
68  self.high_speed_link_duration = config["high_speed_link_duration"]
69  self.high_speed_link_blackout_duration = config["high_speed_link_blackout_duration"]
70  self.updateMM()
71  return config
72  def blackout(self):
73  rospy.loginfo("blackout")
74  self.bands.SetDropAmount(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB,
75  100)
76  SetMM(self.mm2name, self.bands,
77  self.filters, self.filters, self.all_filter_names)
78  self.blackoutp = True
79  self.next_whiteout = rospy.Time.now() + rospy.Duration(randint(1, self.high_speed_link_blackout_duration))
80  def whiteout(self):
81  rospy.loginfo("whiteout")
82  self.bands.SetDropAmount(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB,
83  0)
84  SetMM(self.mm2name, self.bands,
85  self.filters, self.filters, self.all_filter_names)
86  self.blackoutp = False
87  self.next_blackout = rospy.Time.now() + rospy.Duration(self.high_speed_link_duration)
88  def updateMM(self):
89  self.bands.SetDelayAmount(self.LOW_SPEED_BAND_NUM, LANA_to_LANB, 0)
90  self.bands.SetDelayAmount(self.LOW_SPEED_BAND_NUM, LANB_to_LANA, 0)
91  if not self.disable_network_limitation:
92  self.bands.SetRateLimit(self.LOW_SPEED_BAND_NUM, LANA_to_LANB,
94  self.bands.SetRateLimit(self.LOW_SPEED_BAND_NUM, LANB_to_LANA,
96  else:
97  self.bands.SetRateLimit(self.LOW_SPEED_BAND_NUM, LANA_to_LANB,
98  100 * 1000 * 1000)
99  self.bands.SetRateLimit(self.LOW_SPEED_BAND_NUM, LANB_to_LANA,
100  100 * 1000 * 1000)
101  self.bands.SetDelayReorder(self.LOW_SPEED_BAND_NUM, LANB_to_LANA, False)
102  self.bands.SetDelayReorder(self.LOW_SPEED_BAND_NUM, LANA_to_LANB, False)
103  self.bands.SetDelayAmount(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB, 0)
104  self.bands.SetDelayAmount(self.HIGH_SPEED_BAND_NUM, LANB_to_LANA, 0)
105  if not self.disable_network_limitation:
106  self.bands.SetRateLimit(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB,
108  self.bands.SetRateLimit(self.HIGH_SPEED_BAND_NUM, LANB_to_LANA,
110  self.bands.SetDropAmount(self.HIGH_SPEED_BAND_NUM, LANB_to_LANA,
111  100)
112  self.bands.SetDropAmount(5, LANB_to_LANA, 0) #default: all drop
113  self.bands.SetDropAmount(5, LANA_to_LANB, 0) #default: all drop
114  else:
115  self.bands.SetRateLimit(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB,
116  100 * 1000 * 1000)
117  self.bands.SetRateLimit(self.HIGH_SPEED_BAND_NUM, LANB_to_LANA,
118  100 * 1000 * 1000)
119  self.bands.SetDropAmount(self.HIGH_SPEED_BAND_NUM, LANB_to_LANA,
120  0)
121  self.bands.SetDropAmount(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB,
122  0)
123  self.bands.SetDropAmount(5, LANB_to_LANA, 0)
124  self.bands.SetDropAmount(5, LANA_to_LANB, 0)
125  self.bands.SetDelayReorder(self.HIGH_SPEED_BAND_NUM, LANB_to_LANA, False)
126  self.bands.SetDelayReorder(self.HIGH_SPEED_BAND_NUM, LANA_to_LANB, False)
127  SetMM(self.mm2name, self.bands,
128  self.filters, self.filters, self.all_filter_names)
129  rospy.loginfo("updated speed settings")
130 
131 if __name__ == "__main__":
132  rospy.init_node("drc_2015_environment")
134 
135 
def GetAllFilterNames(mm_hostname)
Definition: setfilters.py:34
def SetMM(mm_hostname, bands, a2bfilt_vals, b2afilt_vals, all_filter_names)
Definition: periodic.py:338


mini_maxwell
Author(s): Yusuke Furuta
autogenerated on Tue May 11 2021 02:55:40