Beispiel #1
0
 def try_connect(self):
     if not self.usbc:
         try:
             self.usbc = USBCommunications()
             self.connect_status.set("Connected!")
         except ValueError:
             print("No connection found...")
             self.usbc = None
Beispiel #2
0
class simpleapp_tk(Tkinter.Tk):
    def __init__(self, parent):
        Tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialize()
        self.usbc = None

    def initialize(self):
        self.grid()
        self.connect_status = Tkinter.StringVar(value="No device connected")
        button_connect = Tkinter.Button(self, text=u"Connect to Device", command=self.try_connect)
        button_connect.grid(column=0, row=0, columnspan=2)

        self.connection_label = Tkinter.Label(textvariable=self.connect_status, justify="center")
        self.connection_label.grid(column=2, row=0, columnspan=2)
        # self.spring_constant_scale = Tkinter.Scale(
        #     self, from_=0, to=0.5, resolution=.01)
        # self.spring_constant_scale.grid(column=0, row=2)

        self.wall_angle_scale = Tkinter.Scale(self, from_=-40, to=40, resolution=0.1)
        self.wall_angle_scale.grid(column=1, row=2)

        # self.Ki_constant_scale = Tkinter.Scale(
        #     self, from_=0, to=0.5, resolution=.01)
        # self.Ki_constant_scale.grid(column=2, row=2)

        # self.Kd_constant_scale = Tkinter.Scale(
        #     self, from_=0, to=0.5, resolution=.01)
        # self.Kd_constant_scale.grid(column=3, row=2)

        button_k = Tkinter.Button(self, text=u"Set Wall Angle", command=self.set_wall_ang)
        button_k.grid(column=0, row=4, columnspan=3)

        # button_kp = Tkinter.Button(self, text=u"Set Kp",
        #                         command=self.set_pid_p)
        # button_kp.grid(column=1, row=4)

        # button_ki = Tkinter.Button(self, text=u"Set Ki",
        #                         command=self.set_pid_i)
        # button_ki.grid(column=2, row=4)

        # button_kd = Tkinter.Button(self, text=u"Set Kd",
        #                         command=self.set_pid_d)
        # button_kd.grid(column=3, row=4)

        # self.grid_columnconfigure(0,weight=1)
        self.resizable(True, False)
        self.update()
        self.geometry(self.geometry())
        # self.entry.focus_set()
        # self.entry.selection_range(0, Tkinter.END)

    def try_connect(self):
        if not self.usbc:
            try:
                self.usbc = USBCommunications()
                self.connect_status.set("Connected!")
            except ValueError:
                print("No connection found...")
                self.usbc = None

    def set_wall_ang(self):
        new_constant = self.wall_angle_scale.get()
        self.usbc.set_wall_angle(new_constant)
Beispiel #3
0
class simpleapp_tk(Tkinter.Tk):

    def __init__(self, parent):
        Tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialize()
        self.usbc = None

    def initialize(self):
        self.grid()
        self.connect_status = Tkinter.StringVar(value="No device connected")
        button_connect = Tkinter.Button(self, text=u"Connect to Device",
                                command=self.try_connect)
        button_connect.grid(column=0, row=0, columnspan=2)
        
        self.connection_label = Tkinter.Label(textvariable=self.connect_status, justify='center')
        self.connection_label.grid(column=2, row=0, columnspan=2)

        self.light_stick_scale = Tkinter.Scale(
            self, from_=-40, to=40, resolution=.1)
        self.light_stick_scale.grid(column=0, row=2)

        button_ls = Tkinter.Button(self, text=u"Set Light Stick Angle",
                                command=self.set_ls_ang)
        button_ls.grid(column=0, row=3)

        self.heavy_stick_scale = Tkinter.Scale(
            self, from_=-40, to=40, resolution=.1)
        self.heavy_stick_scale.grid(column=1, row=2)

        button_hs = Tkinter.Button(self, text=u"Set Heavy Stick Angle",
                                command=self.set_hs_ang)
        button_hs.grid(column=1, row=3)

        self.light_slip_scale = Tkinter.Scale(
            self, from_=-40, to=40, resolution=.1)
        self.light_slip_scale.grid(column=2, row=2)

        button_lp = Tkinter.Button(self, text=u"Set Light Slip Angle",
                                command=self.set_lp_ang)
        button_lp.grid(column=2, row=3)

        self.heavy_slip_scale = Tkinter.Scale(
            self, from_=-40, to=40, resolution=.1)
        self.heavy_slip_scale.grid(column=3, row=2)

        button_hp= Tkinter.Button(self, text=u"Set Heavy Slip Angle",
                                command=self.set_ls_ang)
        button_hp.grid(column=3, row=3)

        self.speed_bump_scale = Tkinter.Scale(
            self, from_=-40, to=40, resolution=.1)
        self.speed_bump_scale.grid(column=4, row=2)

        button_hp= Tkinter.Button(self, text=u"Set Speed Bump Angle",
                                command=self.set_sb_ang)
        button_hp.grid(column=4, row=3)
       
        self.resizable(True, False)
        self.update()
        self.geometry(self.geometry())


    def try_connect(self):
        if not self.usbc:
            try:
                self.usbc = USBCommunications()
                self.connect_status.set("Connected!")
            except ValueError:
                print("No connection found...")
                self.usbc = None

    def set_ls_ang(self):
        new_constant = self.light_stick_scale.get()
        self.usbc.set_texture_lt_st(new_constant)

    def set_hs_ang(self):
        new_constant = self.heavy_stick_scale.get()
        self.usbc.set_texture_hv_st(new_constant)

    def set_lp_ang(self):
        new_constant = self.light_slip_scale.get()
        self.usbc.set_texture_lt_sl(new_constant)

    def set_ls_ang(self):
        new_constant = self.heavy_slip_scale.get()
        self.usbc.set_texture_hv_sl(new_constant)

    def set_sb_ang(self):
        new_constant = self.speed_bump_scale.get()
        self.usbc.set_texture_sp(new_constant)
Beispiel #4
0
#! /usr/bin/env python
import sys
import time
import struct

from usb_haptic import USBCommunications

USB_COMMS = USBCommunications()

while 1:
    t0 = time.clock()
    sys.stdout.write('\x1b[2J\x1b[1;1f')
    encoder_reading = USB_COMMS.enc_readReg(0x3FFF)
    print encoder_reading
    encoder_reading[1] = encoder_reading[1] & 0x3F
    print encoder_reading
    print struct.unpack("<H", encoder_reading.tostring())
    while time.clock() < t0 + 0.05:
        pass