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
    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
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)
示例#4
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")
示例#5
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())
示例#6
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")