startup_parameters.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: latin-1 -*-
3 import rospy
4 import os.path
5 
6 #Ros
7 from std_msgs.msg import *
8 #~ from ctt_manager_msgs.msg import *
9 #~ from ctt_manager_msgs.srv import *
10 from time import sleep
11 import std_srvs.srv
12 import gd_msgs.msg
13 import gd_msgs.srv
14 
15 global height_pub
16 global center_pub
17 global height
18 global center
19 global input_cmd
20 
21 
22 pub_matA = None
23 pub_matB = None
24 pub_matK = None
25 pub_matL = None
26 height_cm = 0
27 
28 def readFile():
29  global pub_matA
30  global pub_matB
31  global pub_matK
32  global pub_matL
33  global file_directory
34  global height_cm
35 
36  if not os.path.exists("./matrices.txt"):
37  print "Error - the matrices.txt file is not in gd_scripts directory"
38  exit(1)
39  matrixArray = [line.rstrip('\n') for line in open("matrices.txt", 'r')]
40 
41  if len(matrixArray) != 5:
42  print "Error - The matrices.txt file is not correct"
43  exit(1)
44 
45  for matS in xrange(0,len(matrixArray)):
46  matSArray = matrixArray[matS].split(',')
47  f = []
48  for value_mat in matSArray:
49  try:
50  f.append(float(value_mat.replace(" ", "")))
51  except:
52  print "Error - The matrices.txt file is not correct"
53  exit(1)
54 
55  my_array_for_publishing = Float32MultiArray(data=f)
56 
57  if matS == 0:
58  if len(f) != 7:
59  print "Error - The matrices.txt file is not correct"
60  exit(1)
61  pub_matA.publish(my_array_for_publishing)
62  elif matS == 1:
63  if len(f) != 22:
64  print "Error - The matrices.txt file is not correct"
65  exit(1)
66  pub_matB.publish(my_array_for_publishing)
67  elif matS == 2:
68  if len(f) != 16:
69  print "Error - The matrices.txt file is not correct"
70  exit(1)
71  pub_matK.publish(my_array_for_publishing)
72  elif matS == 3:
73  if len(f) != 20:
74  print "Error - The matrices.txt file is not correct"
75  exit(1)
76  pub_matL.publish(my_array_for_publishing)
77  elif matS == 4:
78  if len(f) != 2:
79  print "Error - The matrices.txt file is not correct"
80  exit(1)
81  height_cm = (f[0] + f[1])/2
82 
83  f = [] #clear matrix again
84 
85 
86 def main():
87  global height_pub
88  global center_pub
89  global height
90  global center
91  global input_cmd
92  global pub_matA
93  global pub_matB
94  global pub_matK
95  global pub_matL
96  global isReset
97  global height_cm
98 
99  #~ rospy.init_node('db_manager', anonymous=True)
100  rospy.init_node('configure_params')
101 
102  #configure publishers
103  #~ pub_session = rospy.Publisher("/db/current_session", String, queue_size=10)
104  height_pub = rospy.Publisher("/cmd_height", std_msgs.msg.Float32, queue_size=10)
105  center_pub = rospy.Publisher("/calib_center", std_msgs.msg.Float32, queue_size=10)
106 
107  pub_matA = rospy.Publisher("/matrixA", Float32MultiArray, queue_size=10)
108  pub_matB = rospy.Publisher("/matrixB", Float32MultiArray, queue_size=10)
109  pub_matK = rospy.Publisher("/matrixK", Float32MultiArray, queue_size=10)
110  pub_matL = rospy.Publisher("/matrixL", Float32MultiArray, queue_size=10)
111 
112  #configure services
113  #~ id_alert_srv = rospy.ServiceProxy('/db/open_alert', ctt_manager_msgs.srv.AlertId)
114  #~ srv_rsp = id_alert_srv(json_data)
115  set_input_srv = rospy.ServiceProxy('/set_input', gd_msgs.srv.SetInput)
116  init_balance_srv = rospy.ServiceProxy('/init_balance', std_srvs.srv.Empty)
117 
118 
119  #Init
120  rospy.sleep(0.2)
121  readFile()
122  height_pub.publish(height_cm)
123  #print height_cm
124  center_pub.publish(center)
125  #call services
126  # from PC
127  rospy.sleep(2)
128  set_input_rsp = set_input_srv(input_cmd)
129  # from RC
130  #~ srv_rsp = set_input_srv({data: 1})
131  init_balance_rsp = init_balance_srv()
132 
133 
134  rospy.sleep(2)
135 
136  #~ rospy.spin()
137 
138 
139 if __name__ == '__main__':
140 
141  if len(sys.argv) == 3:
142  #height = float(sys.argv[1])
143  center = float(sys.argv[1])
144  input_cmd = float(sys.argv[2])
145  else:
146  print "Error - The script needs 2 argv: <IMU-Calibration> <PC(0)/RC(1)>"
147  sys.exit(1)
148  main()
149 
150 


gd_msgs
Author(s):
autogenerated on Mon Jun 10 2019 13:19:18