Ejemplo n.º 1
0
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        analog.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

try:
    print("Enabling Analog output channel 0...")
    analog.setEnabled(0, True)
    sleep(1)

    print("Enabling Analog output channel 0...")
    analog.setEnabled(1, True)
    sleep(1)

    #print("Set analog output voltage to +5.00V...")
    #analog.setVoltage(0, 5.00)
    #sleep(5)

    #print("Set analog output voltage to -5.00V...")
    #analog.setVoltage(0, -5.00)
    #sleep(5)

    #print("Set analog output voltage to +0.00V...")
Ejemplo n.º 2
0
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        analog.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

try:
    print("Enabling Analog output channel 0...")
    analog.setEnabled(0, True)
    sleep(5)

    print("Set analog output voltage to +5.00V...")
    analog.setVoltage(0, 5.00)
    sleep(5)

    print("Set analog output voltage to -5.00V...")
    analog.setVoltage(0, -5.00)
    sleep(5)

    print("Set analog output voltage to +0.00V...")
    analog.setVoltage(0, 0.00)
    sleep(5)

    print("Disabling Analog output channel 0...")
Ejemplo n.º 3
0
class PhidgetsAnalogOut:

    def __init__(self, topic_1_subscriber=None, topic_2_subscriber=None, topic_publisher=None, channel_1=0, channel_2=0, pulselength=0, pulseinterval=0, pulse=False, serial_number=-1):
        ##########################################################
        #Create an analog out object
        try:
            self.analog = Analog()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)
        try:
            if serial_number != -1:
                self.analog.openPhidget(serial_number)
            else:
                self.analog.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        rospy.sleep(1)
        ###########################################################
        
        self.channel_1 = channel_1
        self.channel_2 = channel_2
        self.pulselength = pulselength
        self.pulseinterval = pulseinterval
        self.pulse = pulse
        self.voltage = 0
        
        self.minsleeptime = 0.05
        
        for channel in [self.channel_1, self.channel_2]:
            self.analog.setEnabled(channel, True)
        
        self.subscriber_1 = rospy.Subscriber(topic_1_subscriber, Float32, self.subscriber_1_callback)
        self.subscriber_2 = rospy.Subscriber(topic_2_subscriber, Float32, self.subscriber_2_callback)
        self.publisher = rospy.Publisher(topic_publisher, Float32)
        
        nodename = 'phidgets_chrimson_analog'
        rospy.init_node(nodename, anonymous=True)
        
    def subscriber_1_callback(self, data):
        self.voltage = data.data
        if not self.pulse:
            self.analog.setVoltage(self.channel_1, self.voltage)
            self.publisher.publish(Float32(self.voltage))
            rospy.sleep(self.minsleeptime)
    
    def subscriber_2_callback(self, data):
        self.voltage = data.data
        if not self.pulse:
            self.analog.setVoltage(self.channel_2, self.voltage)
            self.publisher.publish(Float32(self.voltage))
            rospy.sleep(self.minsleeptime)
        
    def pulse_train(self):
        if self.voltage != 0:
            self.analog.setVoltage(self.channel, self.voltage)
            self.publisher.publish(Float32(self.voltage))
            rospy.sleep(self.pulselength)
            self.publisher.publish(Float32(self.voltage))
            
            self.analog.setVoltage(self.channel, 0)
            self.publisher.publish(Float32(0))
            rospy.sleep(self.pulseinterval - self.pulselength)
            self.publisher.publish(Float32(0))
            
        else:
            self.analog.setVoltage(self.channel, 0)
            self.publisher.publish(Float32(0))
            rospy.sleep(self.minsleeptime)
    
        return
        
    def main(self):
        if self.pulse:
            while not rospy.is_shutdown():
                self.pulse_train()
        else:
            rospy.spin()
Ejemplo n.º 4
0
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        analog.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

try:
    print("Enabling Analog output channel 0...")
    analog.setEnabled(0, True)
    sleep(5)

    print("Set analog output voltage to +5.00V...")
    analog.setVoltage(0, 5.00)
    sleep(5)

    print("Set analog output voltage to -5.00V...")
    analog.setVoltage(0, -5.00)
    sleep(5)

    print("Set analog output voltage to +0.00V...")
    analog.setVoltage(0, 0.00)
    sleep(5)

    print("Disabling Analog output channel 0...")
Ejemplo n.º 5
0
class AnalogOut(object):
    """ Class wraps language around the  PhidgetAnalog 4-Output
        ID: 1002_0 analog output device.
    """
    def __init__(self, in_serial=None):

        # http://victorlin.me/posts/2012/08/26/\
        # good-logging-practice-in-python
        self.log = logging.getLogger(__name__)
        if in_serial != None:
            # On odroid C1, int conversion raises null byte in argument
            # strip out the null byte first
            in_serial = in_serial.strip('\0')
            self._serial = int(in_serial)
        else:
            self._serial = None
        self.log.debug("Start of phidgeter with serial: %s" % in_serial)

    def open_phidget(self):
        self.log.debug("Attempting to open phidget")

        self.interface = Analog()

        if self._serial != None:
            self.log.debug("Attempt to open serial: %s" % self._serial)
            self.interface.openPhidget(self._serial)
        else:
            self.log.debug("Attempt to open first found")
            self.interface.openPhidget()

        wait_interval = 10300
        self.log.debug("Wait for attach %sms" % wait_interval)
        self.interface.waitForAttach(wait_interval)

        self.log.info("Opened phidget")
        return 1

    def close_phidget(self):
        self.log.debug("Attempting to close phidget")
        self.interface.closePhidget()
        self.log.info("Closed phidget")
        return 1

    def change_enable(self, output=0, status=0):
        """ Toggle the enable of the phidget analog output line to
            enable(1) or disable(0) status
        """
        self.interface.setEnabled(output, status)
        return 1

    def open_operate_close(self, output, status):
        """ Open the phidget, change the enable status of the analog
            output, close phidget.
        """
        self.open_phidget()
        result = self.change_enable(output, status)
        self.close_phidget()
        return result

    def open_toggle_close(self, output):
        """ Find the current enable status of the specified output, and
            set the status to the opposite.
        """
        self.open_phidget()
        curr_state = self.interface.getEnabled(output)
        res_volt = self.interface.setVoltage(output, 3.3)
        result = self.change_enable(output, not curr_state)
        self.close_phidget()
        return result

    def zero_enable(self):
        return self.open_operate_close(output=0, status=1)

    def zero_disable(self):
        return self.open_operate_close(output=0, status=0)

    def zero_toggle(self):
        return self.open_toggle_close(output=0)

    def two_enable(self):
        return self.open_operate_close(output=2, status=1)

    def two_disable(self):
        return self.open_operate_close(output=2, status=0)

    def two_toggle(self):
        return self.open_toggle_close(output=2)
Ejemplo n.º 6
0
class PhidgetsAnalogOut:
    def __init__(self,
                 topic_1_subscriber=None,
                 topic_2_subscriber=None,
                 topic_publisher=None,
                 channel_1=0,
                 channel_2=0,
                 pulselength=0,
                 pulseinterval=0,
                 pulse=False,
                 serial_number=-1):
        ##########################################################
        #Create an analog out object
        try:
            self.analog = Analog()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)
        try:
            if serial_number != -1:
                self.analog.openPhidget(serial_number)
            else:
                self.analog.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        rospy.sleep(1)
        ###########################################################

        self.channel_1 = channel_1
        self.channel_2 = channel_2
        self.pulselength = pulselength
        self.pulseinterval = pulseinterval
        self.pulse = pulse
        self.voltage = 0

        self.minsleeptime = 0.05

        for channel in [self.channel_1, self.channel_2]:
            self.analog.setEnabled(channel, True)

        self.subscriber_1 = rospy.Subscriber(topic_1_subscriber, Float32,
                                             self.subscriber_1_callback)
        self.subscriber_2 = rospy.Subscriber(topic_2_subscriber, Float32,
                                             self.subscriber_2_callback)
        self.publisher = rospy.Publisher(topic_publisher, Float32)

        nodename = 'phidgets_chrimson_analog'
        rospy.init_node(nodename, anonymous=True)

    def subscriber_1_callback(self, data):
        self.voltage = data.data
        if not self.pulse:
            self.analog.setVoltage(self.channel_1, self.voltage)
            self.publisher.publish(Float32(self.voltage))
            rospy.sleep(self.minsleeptime)

    def subscriber_2_callback(self, data):
        self.voltage = data.data
        if not self.pulse:
            self.analog.setVoltage(self.channel_2, self.voltage)
            self.publisher.publish(Float32(self.voltage))
            rospy.sleep(self.minsleeptime)

    def pulse_train(self):
        if self.voltage != 0:
            self.analog.setVoltage(self.channel, self.voltage)
            self.publisher.publish(Float32(self.voltage))
            rospy.sleep(self.pulselength)
            self.publisher.publish(Float32(self.voltage))

            self.analog.setVoltage(self.channel, 0)
            self.publisher.publish(Float32(0))
            rospy.sleep(self.pulseinterval - self.pulselength)
            self.publisher.publish(Float32(0))

        else:
            self.analog.setVoltage(self.channel, 0)
            self.publisher.publish(Float32(0))
            rospy.sleep(self.minsleeptime)

        return

    def main(self):
        if self.pulse:
            while not rospy.is_shutdown():
                self.pulse_train()
        else:
            rospy.spin()