random_connection.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import roslib
3 roslib.load_manifest('mini_maxwell')
4 import rospy
5 import sys
6 import random
7 import os
8 
9 import rospkg
10 rospack = rospkg.RosPack()
11 sys.path.append(rospack.get_path('mini_maxwell') + "/scripts")
12 
13 from mm2client import *
14 from dynamic_reconfigure.server import Server as DynamicReconfigureServer
15 from mini_maxwell.cfg import RosClientConfig as ConfigType
16 
18  def __init__(self):
19  MM_REV = 12
20  if MM_REV >= 12:
21  # Read the current settings from the Mini Maxwell
22  try:
23  self.bnds = GetCurrentBands(mm2name)
24  except:
25  self.bnds = Bands()
26  else: # MM_REV < 12
27  self.bnds = Bands()
28 
29  # Get parameter
30  self.mm2name = rospy.get_param('~ip', '192.168.0.5')
31  self.round_trip = rospy.get_param('~round_trip', 500) #500ms
32  self.rate_limit = rospy.get_param('~rate_limit', 100000000) #100kbps
33  self.connection_A = True
34  self.connection_B = True
35  self.band_number = 5
36 
37  rospy.loginfo('mm2 hostname or ip = %s', self.mm2name)
38 
39  # Create a dynamic reconfigure server.
40  self.server = DynamicReconfigureServer(ConfigType, self.reconfigure)
41  rospy.Timer(rospy.Duration(1), self.changeConnection)
42  rospy.spin()
43 
44  def reconfigure(self, config, level):
45  self.round_trip = config["round_trip"]
46  self.rate_limit = config["rate_limit"]
47 
48  # Return the new variables.
49  self.updateMM()
50  return config
51 
52  def changeConnection(self, event):
53  present_connection_A = self.connection_A
54  present_connection_B = self.connection_B
55 
56  if random.randint(0, 1):
57  self.connection_A = True
58  rospy.loginfo('A: Connected')
59  else:
60  self.connection_A = False
61  rospy.loginfo('A: Not connected')
62 
63  if random.randint(0, 1):
64  self.connection_B = True
65  rospy.loginfo('B: Connected')
66  else:
67  self.connection_B = False
68  rospy.loginfo('B: Not connected')
69  #self.connection_A = False
70  #self.connection_B = False
71  self.updateMM()
72 
73  def updateMM(self):
74  self.bnds.SetDelayAmount(self.band_number, True, self.round_trip)
75  self.bnds.SetDelayAmount(self.band_number, False, self.round_trip)
76  if self.connection_A:
77  rate_limit_A = self.rate_limit
78  else:
79  rate_limit_A = 128 # minimum value
80 
81  if self.connection_B:
82  rate_limit_B = self.rate_limit
83  else:
84  rate_limit_B = 128 # minimum value
85 
86  self.bnds.SetRateLimit(self.band_number, True, rate_limit_A)
87  self.bnds.SetRateLimit(self.band_number, False, rate_limit_B)
88  self.bnds.SetDelayReorder(self.band_number, True, False)
89  self.bnds.SetDelayReorder(self.band_number, False, False)
90 
91  rospy.loginfo('round_trip = %s', self.round_trip)
92  rospy.loginfo('rate_limit_A = %s', rate_limit_A)
93  rospy.loginfo('rate_limit_B = %s', rate_limit_B)
94  #update MM setting
95  ChangeBandsOnMM(self.bnds, self.mm2name)
96 
97 
98 if __name__ == '__main__':
99  rospy.init_node('mini_maxwell_rondom_connection')
100 
101  try:
103  except rospy.ROSInterruptException: pass
def ChangeBandsOnMM(bandsobj, mm2host)
Definition: mm2client.py:479
def GetCurrentBands(mm2name)
Definition: mm2client.py:446
def reconfigure(self, config, level)


mini_maxwell
Author(s): Yusuke Furuta
autogenerated on Wed Jul 10 2019 03:47:09