Example #1
0
    def __init__(self, master, initial_name, move_pos_text, move_neg_text, serial_number, port, color, amp, vel):
        frame = Frame(master, borderwidth=2, relief=SUNKEN, bg=color)
        frame.pack()
        self.master = master
        self.frame_name = StringVar()
        self.frame_name.set(initial_name)
        self.fontType = "Comic Sans"

        #Set the parameters for the axis
        self.current_limit = amp          #2 to 25A
        self.max_velocity = vel           #0 to 1
        self.acceleration = 1         #0.1 to 100
        self.invert = FALSE             #TRUE or FALSE
        self.axis_name = initial_name
        self.move_pos_text  = move_pos_text
        self.move_neg_text = move_neg_text
        self.current_text = StringVar()

        self.jog_pos_btn = Button(frame, text=self.move_pos_text)
        self.jog_neg_btn = Button(frame, text=self.move_neg_text)
        self.configure_btn = Button(frame, text="CONFIGURE", font=(self.fontType,6), command=lambda: self.configure())
        self.current = Entry(frame, width=5, state=DISABLED, textvariable=self.current_text)
        self.speed = Scale(frame, orient=HORIZONTAL, from_=0.01, to=1, resolution=.01, bg=color, label="      Axis Speed", highlightthickness=0)
        self.custom_label = Label(frame, textvariable=self.frame_name, font=(self.fontType, 14), bg=color)
        self.label = Label(frame, text=initial_name, bg=color)

        self.speed.set(0.25)
        frame.rowconfigure(0, minsize=30)
        self.custom_label.grid(row=0, column=0, columnspan=2, sticky=S)
        self.jog_pos_btn.grid(column=0, row=1, pady=10)
        self.jog_neg_btn.grid(column=0, row=2, pady=10)
        self.current.grid(column=0, row=3,pady=5)
        self.speed.grid(column=0, row=4, padx=20)
        self.configure_btn.grid(column=0, row=5, pady=5)
        self.label.grid(column=0, row=6)

        #Connect to Phidget Motor Driver
        self.axis = DCMotor()
        self.axis.setDeviceSerialNumber(serial_number)
        self.axis.setIsHubPortDevice(False)
        self.axis.setHubPort(port)
        self.axis.setChannel(0)
        self.axis.openWaitForAttachment(5000)
        self.axis.setAcceleration(self.acceleration)

        self.axis_current = CurrentInput()
        self.axis_current.setDeviceSerialNumber(serial_number)
        self.axis_current.setIsHubPortDevice(False)
        self.axis_current.setHubPort(port)
        self.axis_current.setChannel(0)
        self.axis_current.openWaitForAttachment(5000)
        self.axis_current.setDataInterval(200)
        self.axis_current.setCurrentChangeTrigger(0.0)
        self.update_current()

        #Bind user button press of jog button to movement method
        self.jog_pos_btn.bind('<ButtonPress-1>', lambda event: self.jog("+"))
        self.jog_pos_btn.bind('<ButtonRelease-1>', lambda event: self.jog("0"))
        self.jog_neg_btn.bind('<ButtonPress-1>', lambda event: self.jog("-"))
        self.jog_neg_btn.bind('<ButtonRelease-1>', lambda event: self.jog("0"))
class AxisFrame:
    def __init__(self, master, initial_name, move_pos_text, move_neg_text,
                 serial_number, port, color, amp, vel):
        frame = Frame(master, borderwidth=2, relief=SUNKEN, bg=color)
        frame.pack()
        self.master = master
        self.frame_name = StringVar()
        self.frame_name.set(initial_name)
        self.fontType = "Comic Sans"

        #Set the parameters for the axis
        self.current_limit = amp  #2 to 25A
        self.max_velocity = vel  #0 to 1
        self.acceleration = 1  #0.1 to 100
        self.invert = FALSE  #TRUE or FALSE
        self.axis_name = initial_name
        self.move_pos_text = move_pos_text
        self.move_neg_text = move_neg_text
        self.current_text = StringVar()

        self.jog_pos_btn = Button(frame, text=self.move_pos_text)
        self.jog_neg_btn = Button(frame, text=self.move_neg_text)
        self.configure_btn = Button(frame,
                                    text="CONFIGURE",
                                    font=(self.fontType, 6),
                                    command=lambda: self.configure())
        self.current = Entry(frame,
                             width=5,
                             state=DISABLED,
                             textvariable=self.current_text)
        self.speed = Scale(frame,
                           orient=HORIZONTAL,
                           from_=0.01,
                           to=1,
                           resolution=.01,
                           bg=color,
                           label="      Axis Speed",
                           highlightthickness=0)
        self.custom_label = Label(frame,
                                  textvariable=self.frame_name,
                                  font=(self.fontType, 14),
                                  bg=color)
        self.label = Label(frame, text=initial_name, bg=color)

        self.speed.set(0.25)
        frame.rowconfigure(0, minsize=30)
        self.custom_label.grid(row=0, column=0, columnspan=2, sticky=S)
        self.jog_pos_btn.grid(column=0, row=1, pady=10)
        self.jog_neg_btn.grid(column=0, row=2, pady=10)
        self.current.grid(column=0, row=3, pady=5)
        self.speed.grid(column=0, row=4, padx=20)
        self.configure_btn.grid(column=0, row=5, pady=5)
        self.label.grid(column=0, row=6)

        #Connect to Phidget Motor Driver
        self.axis = DCMotor()
        self.axis.setDeviceSerialNumber(serial_number)
        self.axis.setIsHubPortDevice(False)
        self.axis.setHubPort(port)
        self.axis.setChannel(0)
        self.axis.openWaitForAttachment(5000)
        self.axis.setAcceleration(self.acceleration)

        self.axis_current = CurrentInput()
        self.axis_current.setDeviceSerialNumber(serial_number)
        self.axis_current.setIsHubPortDevice(False)
        self.axis_current.setHubPort(port)
        self.axis_current.setChannel(0)
        self.axis_current.openWaitForAttachment(5000)
        self.axis_current.setDataInterval(200)
        self.axis_current.setCurrentChangeTrigger(0.0)
        self.update_current()

        #Bind user button press of jog button to movement method
        self.jog_pos_btn.bind('<ButtonPress-1>', lambda event: self.jog("+"))
        self.jog_pos_btn.bind('<ButtonRelease-1>', lambda event: self.jog("0"))
        self.jog_neg_btn.bind('<ButtonPress-1>', lambda event: self.jog("-"))
        self.jog_neg_btn.bind('<ButtonRelease-1>', lambda event: self.jog("0"))

    def jog(self, direction):
        #Calculate the speed as a percentage of the maximum velocity
        velocity = float(self.speed.get()) * self.max_velocity
        #Apply invert if necessary
        if self.invert == TRUE:
            velocity *= -1

        #Command Movement
        if direction == "+":
            self.axis.setTargetVelocity(velocity)
        elif direction == "-":
            self.axis.setTargetVelocity(-1 * velocity)
        elif direction == "0":
            self.axis.setTargetVelocity(0)

    def update_current(self):
        self.current_text.set(abs(round(self.axis_current.getCurrent(), 3)))
        root.after(200, self.update_current)

    def configure(self):
        #current_limit, max_velocity, acceleration, invert
        self.window = popupWindow(self.master, self.current_limit,
                                  self.max_velocity, self.acceleration,
                                  self.invert)
        self.configure_btn.config(state=DISABLED)
        self.master.wait_window(self.window.top)
        self.configure_btn.config(state=NORMAL)

        #Set the new parameters from the configuration window
        self.current_limit = self.window.current_limit
        self.max_velocity = self.window.max_velocity
        self.acceleration = self.window.acceleration
        self.invert = self.window.invert.get()

        #Update Phidget parameters
        self.axis.setCurrentLimit(self.current_limit)
        self.axis.setAcceleration(self.acceleration)
    def __init__(self):
    	self.current_publisher = rospy.Publisher('CurrentSensor/battery_current_draw', Float64, queue_size=10)
    	self._hz = rospy.get_param('~hz' , 50)
    	try:
            """
            * Allocate a new Phidget Channel object
            """
            ch = CurrentInput()         
            
            channelInfo = ChannelInfo()
            channelInfo.deviceSerialNumber = 539331
            channelInfo.hubPort = 2
            channelInfo.isHubPortDevice = 0
            channelInfo.channel = 0
	    
            ch.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
            ch.setHubPort(channelInfo.hubPort)
            ch.setIsHubPortDevice(channelInfo.isHubPortDevice)
            ch.setChannel(channelInfo.channel)  
             
            ch.setOnAttachHandler(onAttachHandler)
            ch.setOnDetachHandler(onDetachHandler)
            ch.setOnErrorHandler(onErrorHandler)
            ch.setOnCurrentChangeHandler(onCurrentChangeHandler)
            
            """
            * Open the channel with a timeout
            """
            
            print("\nOpening and Waiting for Attachment...")
            
            try:
                ch.openWaitForAttachment(5000)
            except PhidgetException as e:
                PrintOpenErrorMessage(e, ch)
                raise EndProgramSignal("Program Terminated: Open Failed")
        except:
            pass
Example #4
0
def plugin_reconfigure(handle, new_config):
    """ Reconfigures the plugin

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    """
    _LOGGER.info("Old config for wind_turbine plugin {} \n new config {}".format(handle, new_config))
    # Shutdown sensors 
    try: 
        handle['humidity'].close() 
        handle['temperature'].close()
        handle['current'].close() 
        handle['encoder'].close() 
        handle['accelerometer'].close()  
        handle['gyroscope'].close() 
        handle['magnetometer'].close() 
    except Exception as ex:
        _LOGGER.exception("wind_turbine exception: {}".format(str(ex)))
        raise ex
    time.sleep(5) 
    new_handle = copy.deepcopy(new_config)
    try: 
        # check if temp/humidity sensor is enabled. If so restart it 
        if new_handle['tempHumEnable']['value'] == 'true': 
            new_handle['humidity'] = HumiditySensor()
            new_handle['humidity'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['humidity'].setHubPort(int(new_handle['tempHumPort']['value']))
            new_handle['humidity'].setIsHubPortDevice(False)
            new_handle['humidity'].setChannel(0)
            new_handle['humidity'].openWaitForAttachment(5000)
            try:
                new_handle['humidity'].getHumidity()
            except Exception:
                pass

            new_handle['temperature'] = TemperatureSensor()
            new_handle['temperature'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['temperature'].setHubPort(int(new_handle['tempHumPort']['value']))
            new_handle['temperature'].setIsHubPortDevice(False)
            new_handle['temperature'].setChannel(0)
            new_handle['temperature'].openWaitForAttachment(5000)
            try:
                new_handle['temperature'].getTemperature()
            except Exception:
                pass

        # check if current sensor is enabled, if so restart it 
        if new_handle['currentEnable']['value'] == 'true':
            new_handle['current'] = CurrentInput()
            new_handle['current'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['current'].setHubPort(int(new_handle['currentPort']['value']))
            new_handle['current'].setIsHubPortDevice(False)
            new_handle['current'].setChannel(0)
            new_handle['current'].openWaitForAttachment(5000)
            try:
                new_handle['current'].getCurrent()
            except Exception:
                pass

        # check if encoder sensor is enabled  
        if new_handle['encoderEnable']['value'] == 'true':
            new_handle['encoder'] = Encoder()
            new_handle['encoder'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['encoder'].setHubPort(int(new_handle['encoderPort']['value']))
            new_handle['encoder'].setIsHubPortDevice(False)
            new_handle['encoder'].setChannel(0)
            new_handle['encoder'].openWaitForAttachment(5000)
            new_handle['encoder'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    new_handle['encoder'].getPosition()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break

        # check if accelerometer is enabled
        if new_handle['accelerometerEnable']['value'] == 'true':
            new_handle['accelerometer'] = Accelerometer()
            new_handle['accelerometer'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['accelerometer'].setHubPort(int(new_handle['spatialPort']['value']))
            new_handle['accelerometer'].setIsHubPortDevice(False)
            new_handle['accelerometer'].setChannel(0)
            new_handle['accelerometer'].openWaitForAttachment(5000)
            new_handle['accelerometer'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    new_handle['accelerometer'].getAcceleration()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break
        # check if gyroscope is enabled 
        if new_handle['gyroscopeEnable']['value'] == 'true':
            new_handle['gyroscope'] = Gyroscope()
            new_handle['gyroscope'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['gyroscope'].setHubPort(int(new_handle['spatialPort']['value']))
            new_handle['gyroscope'].setIsHubPortDevice(False)
            new_handle['gyroscope'].setChannel(0)
            new_handle['gyroscope'].openWaitForAttachment(5000)
            new_handle['gyroscope'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    new_handle['gyroscope'].getAngularRate()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break
        # check if magnetometer enable is enabled 
        if new_handle['magnetometerEnable']['value'] == 'true':
            new_handle['magnetometer'] = Magnetometer()
            new_handle['magnetometer'].setDeviceSerialNumber(int(new_handle['hubSN']['value']))
            new_handle['magnetometer'].setHubPort(int(new_handle['spatialPort']['value']))
            new_handle['magnetometer'].setIsHubPortDevice(False)
            new_handle['magnetometer'].setChannel(0)
            new_handle['magnetometer'].openWaitForAttachment(5000)
            new_handle['magnetometer'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    new_handle['magnetometer'].getMagneticField()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break

        # check if hub has changed, if so init restart 
        if new_handle['hubSN']['value'] != handle['hubSN']['value']:
            new_handle['restart'] = 'yes'
        else:
            new_handle['restart'] = 'no'
    except Exception as ex:
        _LOGGER.exception("wind_turbine exception: {}".format(str(ex)))
        raise ex

    # counter to know when to run process
    new_handle['tempHumCount'] = 0
    new_handle['currentCount'] = 0
    new_handle['encoderCount'] = 0
    new_handle['accelerometerCount'] = 0
    new_handle['gyroscopeCount'] = 0
    new_handle['magnetometerCount'] = 0

    # counter of last encoder value
    new_handle['encoderPreviousValue'] = handle['encoderPreviousValue']

    return new_handle
Example #5
0
def plugin_init(config):
    """ Initialise the plugin.
    Args:
        config: JSON configuration document for the South plugin configuration category
    Returns:
        data: JSON object to be used in future calls to the plugin
    Raises:
    """
    try: 
        data = copy.deepcopy(config)
        if data['tempHumEnable']['value'] == 'true':
            data['humidity'] = HumiditySensor()
            data['humidity'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['humidity'].setHubPort(int(data['tempHumPort']['value']))
            data['humidity'].setIsHubPortDevice(False)
            data['humidity'].setChannel(0)
            data['humidity'].openWaitForAttachment(5000)
            try:
                data['humidity'].getHumidity()
            except Exception:
                pass

            data['temperature'] = TemperatureSensor()  
            data['temperature'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['temperature'].setHubPort(int(data['tempHumPort']['value']))
            data['temperature'].setIsHubPortDevice(False)
            data['temperature'].setChannel(0)
            data['temperature'].openWaitForAttachment(5000)
            try:
                data['temperature'].getTemperature()
            except Exception:
                pass

        if data['currentEnable']['value'] == 'true': 
            data['current'] = CurrentInput() 
            data['current'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['current'].setHubPort(int(data['currentPort']['value']))
            data['current'].setIsHubPortDevice(False)
            data['current'].setChannel(0)
            data['current'].openWaitForAttachment(5000)
            try:
                data['current'].getCurrent()
            except Exception:
                pass

        if data['encoderEnable']['value'] == 'true': 
            data['encoder'] = Encoder()
            data['encoder'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['encoder'].setHubPort(int(data['encoderPort']['value']))
            data['encoder'].setIsHubPortDevice(False)
            data['encoder'].setChannel(0)
            data['encoder'].openWaitForAttachment(5000)
            data['encoder'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    data['encoder'].getPosition()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break
    
        if data['accelerometerEnable']['value'] == 'true': 
            data['accelerometer'] = Accelerometer()
            data['accelerometer'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['accelerometer'].setHubPort(int(data['spatialPort']['value']))
            data['accelerometer'].setIsHubPortDevice(False)
            data['accelerometer'].setChannel(0)
            data['accelerometer'].openWaitForAttachment(5000)
            data['accelerometer'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    data['accelerometer'].getAcceleration()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break

        if data['gyroscopeEnable']['value'] == 'true': 
            data['gyroscope'] = Gyroscope()
            data['gyroscope'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['gyroscope'].setHubPort(int(data['spatialPort']['value']))
            data['gyroscope'].setIsHubPortDevice(False)
            data['gyroscope'].setChannel(0)
            data['gyroscope'].openWaitForAttachment(5000)
            data['gyroscope'].setDataInterval(20)
            i = 0
            while i < 120:
                try:
                    data['gyroscope'].getAngularRate()
                except Exception:
                    time.sleep(1)
                    i += 1
                else:
                    break

        if data['magnetometerEnable']['value'] == 'true': 
            data['magnetometer'] = Magnetometer()
            data['magnetometer'].setDeviceSerialNumber(int(data['hubSN']['value']))
            data['magnetometer'].setHubPort(int(data['spatialPort']['value']))
            data['magnetometer'].setIsHubPortDevice(False)
            data['magnetometer'].setChannel(0)
            data['magnetometer'].openWaitForAttachment(5000)
            data['magnetometer'].setDataInterval(20)
            i = 0 
            while i < 120: 
                try: 
                    data['magnetometer'].getMagneticField() 
                except Exception:
                    time.sleep(1)
                    i += 1
                else: 
                    break 

    except Exception as ex:
        _LOGGER.exception("wind_turbine exception: {}".format(str(ex)))
        raise ex

    # counter to know when to run process 
    data['tempHumCount'] = 0 
    data['currentCount'] = 0 
    data['encoderCount'] = 0 
    data['accelerometerCount'] = 0 
    data['gyroscopeCount'] = 0 
    data['magnetometerCount'] = 0 

    # counter of last encoder value 
    data['encoderPreviousValue'] = 0
    data['encoderPreviousTime'] = 0  
    return data
Example #6
0
B = 0
C = 0

ACCEL = 2

#Line required to look for Phidget devices on the network
Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE)

if A:
    # Motor A: Setup Motor Control and Motor Current
    mtrA = DCMotor()
    mtrA.setDeviceSerialNumber(534830)
    mtrA.openWaitForAttachment(1000)
    mtrA.setAcceleration(ACCEL)

    aCur = CurrentInput()
    aCur.setDeviceSerialNumber(534830)
    aCur.openWaitForAttachment(1000)

if B:
    # Motor B: Setup Motor Control and Motor Current
    mtrB = DCMotor()
    mtrB.setDeviceSerialNumber(465371)
    mtrB.openWaitForAttachment(1000)
    mtrB.setAcceleration(ACCEL)

    bCur = CurrentInput()
    bCur.setDeviceSerialNumber(465371)
    bCur.openWaitForAttachment(1000)

if C:
    def __init__(self):
	self.motor_current_publisher = rospy.Publisher('phidgetsensor/motor_current_draw', Float64, queue_size=10)
	self.voltage_publisher = rospy.Publisher('phidgetsensor/battery_voltage' , Float64, queue_size=10)
	self.battery_current_publisher = rospy.Publisher('phidgetsensor/battery_current_draw', Float64, queue_size=10)

	self._hz = 10
	
	#Channel 1 will be the motor_current_draw
	ch1 = CurrentInput()

	channelInfo = ChannelInfo()
	channelInfo.deviceSerialNumber = 539331
	channelInfo.hubPort = 2
	channelInfo.isHubPortDevice = 0
	channelInfo.channel = 0

	ch1.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
        ch1.setHubPort(channelInfo.hubPort)
        ch1.setIsHubPortDevice(channelInfo.isHubPortDevice)
        ch1.setChannel(channelInfo.channel) 

        ch1.setOnAttachHandler(self.onAttachHandler)
        ch1.setOnDetachHandler(self.onDetachHandler)
        ch1.setOnErrorHandler(self.onErrorHandler)
        ch1.setOnCurrentChangeHandler(self.onCurrentChangeHandler_m)
	
	try: 
	    ch1.openWaitForAttachment(5000)
	except PhidgetException as e:
	    PrintOpenErrorMessage(e, ch1)
	    raise EndProgramSignal("Program Terminated: Open ch1 failed")
	#channel 2 will be the battery voltage
	ch2 = VoltageInput()

        channelInfo = ChannelInfo()
        channelInfo.deviceSerialNumber = 539331
        channelInfo.hubPort = 1
        channelInfo.isHubPortDevice = 0
        channelInfo.channel = 0

        ch2.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
        ch2.setHubPort(channelInfo.hubPort)
        ch2.setIsHubPortDevice(channelInfo.isHubPortDevice)
        ch2.setChannel(channelInfo.channel) 

        ch2.setOnAttachHandler(self.onAttachHandler)
        ch2.setOnDetachHandler(self.onDetachHandler)
        ch2.setOnErrorHandler(self.onErrorHandler)
        ch2.setOnVoltageChangeHandler(self.onVoltageChangeHandler)

        try: 
            ch2.openWaitForAttachment(5000)
        except PhidgetException as e:
            PrintOpenErrorMessage(e, ch2)
            raise EndProgramSignal("Program Terminated: Open ch2 failed")

	#channel 3 will be the battery current
	ch3 = CurrentInput()

        channelInfo = ChannelInfo()
        channelInfo.deviceSerialNumber = 539331
        channelInfo.hubPort = 0
        channelInfo.isHubPortDevice = 0
        channelInfo.channel = 0

        ch3.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
        ch3.setHubPort(channelInfo.hubPort)
        ch3.setIsHubPortDevice(channelInfo.isHubPortDevice)
        ch3.setChannel(channelInfo.channel) 

        ch3.setOnAttachHandler(self.onAttachHandler)
        ch3.setOnDetachHandler(self.onDetachHandler)
        ch3.setOnErrorHandler(self.onErrorHandler)
        ch3.setOnCurrentChangeHandler(self.onCurrentChangeHandler_b)
	
        try: 
            ch3.openWaitForAttachment(5000)
        except PhidgetException as e:
            PrintOpenErrorMessage(e, ch3)
            raise EndProgramSignal("Program Terminated: Open ch3 failed")
Example #8
0
"""
Name: Ori Shadmon 
description: code for Spatial sensors (Acceleration, Gyroscope, Magnometer)
URL: https://www.phidgets.com/?tier=3&catid=10&pcid=8&prodid=975
"""

import time
from Phidget22.Devices.CurrentInput import *
from Phidget22.PhidgetException import *
from Phidget22.Phidget import *
from Phidget22.Net import *

ch = CurrentInput()
ch.setDeviceSerialNumber(561266)
ch.setHubPort(3)
ch.setIsHubPortDevice(False)
ch.setChannel(0)
ch.openWaitForAttachment(5000)
try:
    ch.getCurrent()
except Exception as e:
    pass
time.sleep(2)
print(ch.getCurrent())
    def __init__(self):
        self.current_publisher = rospy.Publisher(
            'CurrentSensor/battery_current_draw', Float64, queue_size=10)
        self._hz = rospy.get_param('~hz', 50)
        try:
            """
            * Allocate a new Phidget Channel object
            """
            ch = CurrentInput()

            channelInfo = ChannelInfo()
            channelInfo.deviceSerialNumber = 539331
            channelInfo.hubPort = 2
            channelInfo.isHubPortDevice = 0
            channelInfo.channel = 0

            ch.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
            ch.setHubPort(channelInfo.hubPort)
            ch.setIsHubPortDevice(channelInfo.isHubPortDevice)
            ch.setChannel(channelInfo.channel)

            ch.setOnAttachHandler(onAttachHandler)
            ch.setOnDetachHandler(onDetachHandler)
            ch.setOnErrorHandler(onErrorHandler)
            ch.setOnCurrentChangeHandler(onCurrentChangeHandler)
            """
            * Open the channel with a timeout
            """

            print("\nOpening and Waiting for Attachment...")

            try:
                ch.openWaitForAttachment(5000)
            except PhidgetException as e:
                PrintOpenErrorMessage(e, ch)
                raise EndProgramSignal("Program Terminated: Open Failed")
        except:
            pass
Example #10
0
    def __init__(self):
        self.motor_current_publisher = rospy.Publisher(
            'phidgetsensor/motor_current_draw', Float64, queue_size=10)
        self.voltage_publisher = rospy.Publisher(
            'phidgetsensor/battery_voltage', Float64, queue_size=10)
        self.battery_current_publisher = rospy.Publisher(
            'phidgetsensor/battery_current_draw', Float64, queue_size=10)

        self._hz = 10

        #Channel 1 will be the motor_current_draw
        ch1 = CurrentInput()

        channelInfo = ChannelInfo()
        channelInfo.deviceSerialNumber = 539331
        channelInfo.hubPort = 2
        channelInfo.isHubPortDevice = 0
        channelInfo.channel = 0

        ch1.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
        ch1.setHubPort(channelInfo.hubPort)
        ch1.setIsHubPortDevice(channelInfo.isHubPortDevice)
        ch1.setChannel(channelInfo.channel)

        ch1.setOnAttachHandler(self.onAttachHandler)
        ch1.setOnDetachHandler(self.onDetachHandler)
        ch1.setOnErrorHandler(self.onErrorHandler)
        ch1.setOnCurrentChangeHandler(self.onCurrentChangeHandler_m)

        try:
            ch1.openWaitForAttachment(5000)
        except PhidgetException as e:
            PrintOpenErrorMessage(e, ch1)
            raise EndProgramSignal("Program Terminated: Open ch1 failed")
        #channel 2 will be the battery voltage
        ch2 = VoltageInput()

        channelInfo = ChannelInfo()
        channelInfo.deviceSerialNumber = 539331
        channelInfo.hubPort = 1
        channelInfo.isHubPortDevice = 0
        channelInfo.channel = 0

        ch2.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
        ch2.setHubPort(channelInfo.hubPort)
        ch2.setIsHubPortDevice(channelInfo.isHubPortDevice)
        ch2.setChannel(channelInfo.channel)

        ch2.setOnAttachHandler(self.onAttachHandler)
        ch2.setOnDetachHandler(self.onDetachHandler)
        ch2.setOnErrorHandler(self.onErrorHandler)
        ch2.setOnVoltageChangeHandler(self.onVoltageChangeHandler)

        try:
            ch2.openWaitForAttachment(5000)
        except PhidgetException as e:
            PrintOpenErrorMessage(e, ch2)
            raise EndProgramSignal("Program Terminated: Open ch2 failed")

        #channel 3 will be the battery current
        ch3 = CurrentInput()

        channelInfo = ChannelInfo()
        channelInfo.deviceSerialNumber = 539331
        channelInfo.hubPort = 0
        channelInfo.isHubPortDevice = 0
        channelInfo.channel = 0

        ch3.setDeviceSerialNumber(channelInfo.deviceSerialNumber)
        ch3.setHubPort(channelInfo.hubPort)
        ch3.setIsHubPortDevice(channelInfo.isHubPortDevice)
        ch3.setChannel(channelInfo.channel)

        ch3.setOnAttachHandler(self.onAttachHandler)
        ch3.setOnDetachHandler(self.onDetachHandler)
        ch3.setOnErrorHandler(self.onErrorHandler)
        ch3.setOnCurrentChangeHandler(self.onCurrentChangeHandler_b)

        try:
            ch3.openWaitForAttachment(5000)
        except PhidgetException as e:
            PrintOpenErrorMessage(e, ch3)
            raise EndProgramSignal("Program Terminated: Open ch3 failed")