record_current_and_voltage.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import csv
19 
20 import rospy
21 from cob_phidgets.msg import AnalogSensor
22 
23 def callback(data):
24  #print "voltage=", data.value[1] # voltage sensor is on the second port of the phidgets board
25  #print "current=", data.value[0] # current sensor is on the first port of the phidgets board
26  writer.writerow( ( round((rospy.Time.now() - starttime).to_sec(),5), data.value[1], data.value[0]) )
27 
28 def record():
29  rospy.init_node('record_current_and_voltage')
30  global starttime
31  starttime = rospy.Time.now()
32 
33  global f
34  global writer
35  filename = rospy.get_param("~filename")
36  global port_voltage, port_current
37  port_voltage = rospy.get_param("~port_voltage")
38  port_current = rospy.get_param("~port_current")
39  f = open(filename, 'wt', 1)
40  writer = csv.writer(f)
41  writer.writerow(("time_from_start", "voltage", "current"))
42 
43  rospy.Subscriber("/analog_sensors", AnalogSensor, callback)
44 
45  rospy.spin()
46 
47 if __name__ == '__main__':
48  record()
49 


cob_voltage_control
Author(s): Alexander Bubeck
autogenerated on Wed Apr 7 2021 02:11:57