class ScreenTwo(Screen): joystick = Joystick(0, True) button_state = ObjectProperty(0) def __init__(self, **kwargs): Builder.load_file('ScreenTwo.kv') super(ScreenTwo, self).__init__(**kwargs) self.anim = () def go_back(self): PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene='main', text="Test", pause_duration=1) def animate(self): self.anim = Animation(x=.1, y=.1) & Animation(size=(400, 200)) self.anim.start(self.ids.animate_button) def joy_update(self): while 1: self.ids.joystick.center_x = joystick.get_axis('x') * self.width self.ids.joystick.center_y = joystick.get_axis('y') * -self.height self.ids.joystick.text = "{:.3f} {:.3f}".format( joystick.get_axis('x'), joystick.get_axis('y')) self.button_state = self.joystick.get_button_state(0) sleep(.1) def start_joy_thread(self): Thread(target=self.joy_update, args=()).start()
class MainScreen(Screen): counter = StringProperty("0") toggle = ObjectProperty(False) joystick = Joystick(0, False) X_axis = ObjectProperty(0.0) Y_axis = ObjectProperty(0.0) def joystick_thread(self): while 1: self.joystick.refresh() self.X_axis = self.joystick.get_axis('x') self.Y_axis = self.joystick.get_axis('y') #print(self.X_axis) def start_joystick_Thread(self): Thread(target=self.joystick_thread).start() """ Class to handle the main screen and its associated touch events """ def pressed_counter(self): tempCounter = int(self.counter) tempCounter += 1 self.counter = str(tempCounter) def pressed_motor_toggle(self): self.toggle = not self.toggle def pressed(self): """ Function called on button touch event for button with id: testButton :return: None """ #PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene='main', text="Test", pause_duration=5) PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene='button', text="LOADING BUTTON SCREEN FOR YOU", pause_duration=2) #SCREEN_MANAGER.current = 'button' def admin_action(self): """ Hidden admin button touch event. Transitions to passCodeScreen. This method is called from pidev/kivy/PassCodeScreen.kv :return: None """ SCREEN_MANAGER.current = 'passCode'
class MainScreen(Screen): """ Class to handle the main screen and its associated touch events """ string_count = StringProperty() condition = ObjectProperty() joystick = Joystick(0, True) x_axis = ObjectProperty(0, 0) y_axis = ObjectProperty(0, 0) def joystick_thread(self): while 1: self.joystick.refresh() self.x_axis = self.joystick.get_axis('x') self.y_axis = self.joystick.get_axis('y') self.ids.dog.text = str(self.joystick.get_button_state(0)) def start_Joystick_Thread(self): Thread(target=self.joystick_thread).start() def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) self.count = 0 self.condition = False def pressed(self): self.count = self.count + 1 self.string_count = str(self.count) def press(self): PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene=FARMYARD_SCREEN_NAME, text="Weeeeeee!", pause_duration=1) def motor_pressed(self): self.condition = not self.condition def admin_action(self): """ Hidden admin button touch event. Transitions to passCodeScreen. This method is called from pidev/kivy/PassCodeScreen.kv :return: None """ SCREEN_MANAGER.current = 'passCode'
class Farmyard(Screen): joystick = Joystick(0, True) joy_val_x = ObjectProperty(0) joy_val_y = ObjectProperty(0) joy_trigger_label = ObjectProperty(0) def __init__(self, **kwargs): Builder.load_file('Farmyard.kv') PassCodeScreen.set_transition_back_screen(MAIN_SCREEN_NAME) super(Farmyard, self).__init__(**kwargs) def update(self): while 1: self.joy_val_x = joystick.get_axis('x') self.joy_val_y = joystick.get_axis('y') self.joy_trigger_label = self.joystick.get_button_state(0) sleep(.1) def joy_thread(self): Thread(target=self.update, args=()).start() def transition_back(self): SCREEN_MANAGER.current = MAIN_SCREEN_NAME def back(self): PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene='main', text="Test", pause_duration=5) """ Function called on button touch event for button with id: testButton :return: None """ def animation(self): anim = Animation(x=50, y=50) & Animation(size=(200, 200)) anim.start(self.ids.logo_image_button)
from kivy.properties import ObjectProperty from kivy.uix.slider import Slider from kivy.animation import Animation, AnimationTransition from threading import Thread from time import sleep from pidev.MixPanel import MixPanel from pidev.kivy.PassCodeScreen import PassCodeScreen import pidev.kivy.PauseScreen from pidev.kivy import DPEAButton from pidev.kivy import ImageButton from pidev.Joystick import Joystick MIXPANEL_TOKEN = "x" MIXPANEL = MixPanel("Project Name", MIXPANEL_TOKEN) joystick = Joystick(0, False) SCREEN_MANAGER = ScreenManager() MAIN_SCREEN_NAME = 'main' ADMIN_SCREEN_NAME = 'admin' IMAGE_SCREEN_NAME = 'image' class ProjectNameGUI(App): """ Class to handle running the GUI Application """ def build(self): """ Build the application :return: Kivy Screen Manager instance
from pidev.MixPanel import MixPanel from pidev.kivy.PassCodeScreen import PassCodeScreen from pidev.kivy.PauseScreen import PauseScreen from pidev.kivy import DPEAButton from pidev.kivy import ImageButton MIXPANEL_TOKEN = "x" MIXPANEL = MixPanel("Project Name", MIXPANEL_TOKEN) SCREEN_MANAGER = ScreenManager() MAIN_SCREEN_NAME = 'main' ADMIN_SCREEN_NAME = 'admin' TRANSITION_SCREEN_NAME = 'TransitionScreen' ctr = 1 ctr2 = 0 joystick = Joystick(0, True) class ProjectNameGUI(App): """ Class to handle running the GUI Application """ def build(self): """ Build the application :return: Kivy Screen Manager instance """ return SCREEN_MANAGER Window.clearcolor = (1, 1, 1, 1) # White
from time import sleep import odrive import ODrive_Ease_Lib from pidev.Joystick import Joystick joystick = Joystick(0, False) OD = odrive.find_any() axis_1 = ODrive_Ease_Lib.ODrive_Axis(OD.axis1) axis_0 = ODrive_Ease_Lib.ODrive_Axis(OD.axis0) restricted_length = 20000 def run_x_axis(): pos = axis_1.get_pos() if pos < (full_length - restricted_length) and joystick.get_axis('x') < -.05: axis_1.set_vel(vel_speed * -joystick.get_axis('x')) elif pos > restricted_length and joystick.get_axis('x') > .05: axis_1.set_vel(vel_speed * -joystick.get_axis('x')) else: axis_1.set_vel(0) def run_y_axis():
class JoyScreen(Screen): joystick = Joystick(0, True) nma = ObjectProperty(None) aer = ObjectProperty(None) arm = ObjectProperty(None) now = ObjectProperty(None) gamer = ObjectProperty(None) gamet = ObjectProperty(None) global event1 global event2 global event3 global event4 global a a = 1 global glob glob = 1 global x global ad global keyboard x = 1 global ft ft = 2 def startThread(self): print("Thread") self.gamet.text = "Running using threads." Thread(target=self.threads).start() Thread.daemon = True def _keyboard_closed(self): self._keyboard.unbind(on_key_down=self.arrowcontrol) self._keyboard = None def threads(self): while SCREEN_MANAGER.current == JOY_SCREEN_NAME: self.callback(1) if(x==1): self.cords(1) self.combo(1) self.backroundc(1) sleep(.01) print("Thread ended") def callback(self,dt): print("afdfs") if(self.joystick.get_button_state(1)==1): self.nma.text = "Button 1 on" else: self.nma.text = "Button 1 off" def cords(self,dt): self.arm.text = "x:%f y:%f" % (self.joystick.get_both_axes()[0],self.joystick.get_both_axes()[1]) self.arm.x = self.joystick.get_both_axes()[0]*Window.size[0] * 1/2 self.arm.y = -self.joystick.get_both_axes()[1]*Window.size[1] * 1/2 def backroundc(self,dt): global ft random.seed(ft) if(self.joystick.get_button_state(0)==1): Window.clearcolor = (random.random(),random.random(),random.random(),1) s = self.aer.text self.aer.text = "A" self.aer.text = "%s" % s ft = self.arm.x + self.arm.y def combo(self,dt): list = [1,2,3] if(self.joystick.button_combo_check(list)==1): self.aer.text = "Combo of 123 active" else: self.aer.text = "Combo of 123 not active" def __init__(self, **kwargs): Builder.load_file('joyScreen.kv') super(JoyScreen, self).__init__(**kwargs) self.arm.y = 0 self.arm.x = 0 def hi(self,df): print("hi") def canceled(self): global event1 global event2 global event3 global event4 event1.cancel() event2.cancel() event3.cancel() event4.cancel() print("Clock Canceled") def events(self): print("Clock") self.gamet.text = "Running using clock scheduling." global a a = 2 global event1 global event2 global event3 global event4 event1 = Clock.schedule_interval(self.callback, 1/100) event2 = Clock.schedule_interval(self.combo, 1/100) event4 = Clock.schedule_interval(self.backroundc, 1 / 100) event3 = Clock.schedule_interval(self.cords, 1/100) def yes(self): if(x == 2): self.arrowcontrolon() if(a == 2): self.canceled() # commit this out to switch to thread instead of clock. SCREEN_MANAGER.current = MAIN_SCREEN_NAME def arrowcontrolon(self): global event3 global x global ad global glob if(x == 1): if(a == 2): event3.cancel() self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self.arrowcontrol) self.gamer.text = "Arrow control on" x = 2 else: self._keyboard.release() if(a==2): event3 = Clock.schedule_interval(self.cords, 1/100) self.gamer.text = "Arrow control off" x = 1 def arrowcontrol(self, keyboard, keycode, text, modifiers): self.arm.text = "x:%f y:%f" % (self.arm.x/400, self.arm.y/300) print("%s"% keycode[1]) if(keycode[1]=="w"): if(self.arm.y<300): self.arm.y = self.arm.y + 5 else: self.arm.y = 300 elif(keycode[1]=="s"): if(self.arm.y>(-300)): self.arm.y = self.arm.y - 5 else: self.arm.y = -300 elif(keycode[1]=="d"): if(self.arm.x<400): self.arm.x = self.arm.x + 5 else: self.arm.x = 400 elif (keycode[1]=="a"): if(self.arm.x > (-400)): self.arm.x = self.arm.x - 5 else: self.arm.x = -400 elif (keycode[1] == "up"): if (self.arm.y < 300): self.arm.y = self.arm.y + 20 else: self.arm.y = 300 elif (keycode[1] == "down"): if (self.arm.y > (-300)): self.arm.y = self.arm.y - 20 else: self.arm.y = -300 elif (keycode[1] == "right"): if (self.arm.x < 400): self.arm.x = self.arm.x + 20 else: self.arm.x = 400 elif (keycode[1] == "left"): if (self.arm.x > (-400)): self.arm.x = self.arm.x - 20 else: self.arm.x = -400
from time import sleep import odrive import ODrive_Ease_Lib from pidev.Joystick import Joystick joystick = Joystick(0, False) OD = odrive.find_any() axis = ODrive_Ease_Lib.ODrive_Axis(OD.axis1) if __name__ == '__main__': axis.clear_errors() axis.cpr(4096) axis.calibrate() axis.home_with_vel(-5000, -1.0) print(axis.zero) print(axis.get_pos()) # cpr encoder 8096 length: 112816 full_length = 56427 restricted_length = 10000 middle = full_length / 2 axis.set_vel_limit(250000) switch = True try: while True:
class ProjectNameGUI(App): """ Class to handle running the GUI Application """ def build(self): """ Build the application :return: Kivy Screen Manager instance """ return SCREEN_MANAGER Window.clearcolor = (1, 1, 1, 1) # White jstick = Joystick(number=0, ssh_deploy=False) class ImageScreen(Screen): def ret(self, widg): anim = Animation(size=(400, 400)) + Animation(size=(80, 80)) anim.start(widg) SCREEN_MANAGER.current = MAIN_SCREEN_NAME class MainScreen(Screen): """ Class to handle the main screen and its associated touch events """ def joy_update(self): while True:
class MainScreen(Screen): """ Class to handle the main screen and its associated touch events """ joystick = Joystick(0, True) countButton = ObjectProperty(None) counter = 0 x_position_joystick1 = ObjectProperty() y_position_joystick1 = ObjectProperty() def pressed(self): """ Function called on button touch event for button with id: testButton :return: None """ PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene='main', text="Test", pause_duration=1) def admin_action(self): """ Hidden admin button touch event. Transitions to passCodeScreen. This method is called from pidev/kivy/PassCodeScreen.kv :return: None """ SCREEN_MANAGER.current = 'passCode' def iterateButton(self, val): return str(int(val) + 1) def changeButton(self, val): if val == "On": return "Off" else: return "On" def changeMotorLabel(self, val): if val == "Motor On": return "Motor Off" else: return "Motor On" def goToNewScreen(self): SCREEN_MANAGER.current = NEW_SCREEN def start_joy_thread(self): x = Thread(target=self.updateJoystick) x.start() def updateJoystick(self): while True: # print("hello") self.x_position_joystick1 = self.joystick.get_axis('x') self.ids.PositionJoystick.center_x = (self.x_position_joystick1 * (self.width / 2) + (self.width / 2)) self.y_position_joystick1 = self.joystick.get_axis('y') self.ids.PositionJoystick.center_y = (self.y_position_joystick1 * (self.height / 2) + (self.height / 2)) self.ids.PositionJoystick.text = "x= {:.3f}, y= {:.3f}".format( self.joystick.get_axis('x'), self.joystick.get_axis('y')) sleep(.1)
""" Method to test Odrive with a joystick currently being used for tests with Tippy Maze set up """ from time import sleep import odrive import ODrive_Ease_Lib from pidev.Joystick import Joystick # declaring joystick joystick = Joystick(0, False) # finding the odrive and setting the axis OD = odrive.find_any() axis = ODrive_Ease_Lib.ODrive_Axis(OD.axis0) if __name__ == '__main__': axis.clear_errors() axis.calibrate() # direction of homing determined by the way the ODrive is connected and subject to change axis.home_with_vel(5000, -1.0) print(axis.zero ) # prints the location of the 0 in the raw position of the ODrive print(axis.get_pos(), " ", axis.get_raw_pos()) axis.set_curr_limit(28)
class NewScreen(Screen): if_then = False joystick = Joystick(0, True) def __init__(self, **kwargs): Builder.load_file('NewScreen.kv') super(NewScreen, self).__init__(**kwargs) def thread_function(self): y = threading.Thread(target=self.joystick1, daemon=True) y.start() def joystick1(self): while True: self.ids.location.x = self.joystick.get_axis('x') * (self.width / 2) self.ids.location.y = self.joystick.get_axis('y') * -(self.height / 2) self.ids.location.text = "{:.3f} {:1.3f}".format( self.joystick.get_axis('x'), (self.joystick.get_axis('y'))) for x in range(11): if self.joystick.get_button_state(x) == 1: self.ids.updates.text = str(x) break else: self.ids.updates.text = "No button depressed" if (-.9 * (self.width / 2)) <= self.ids.location.x <= (-.5 * (self.width / 2)) and \ (-.4 * (self.height / 2)) <= self.ids.location.y <= (-.0001 * (self.height / 2)): pass else: self.ids.on.text = "Not Pressed" if (-.9 * (self.width / 2)) <= self.ids.location.x <= (-.5 * (self.width / 2)) and \ (-.4 * (self.height / 2)) <= self.ids.location.y <= (-.0001 * (self.height / 2)) and \ self.joystick.get_button_state(0) == 0 and self.if_then == False: self.if_then = True self.ids.on.text = "Not Pressed" if (-.9 * (self.width / 2)) <= self.ids.location.x <= (-.5 * (self.width / 2)) and \ (-.4 * (self.height / 2)) <= self.ids.location.y <= (-.0001 * (self.height / 2)) and \ self.if_then and self.joystick.get_button_state(0) == 1: self.ids.on.text = "Pressed!" self.if_then = False time.sleep(.1) def mainscreen(self): SCREEN_MANAGER.current = MAIN_SCREEN_NAME def animation(self): self.anim = Animation(x=50, y=100, duration=2.) & Animation( size=(200, 200), duration=2.) for w in range(3): self.anim += Animation(x=750, y=300, duration=.05) & Animation( size=(50, 50), duration=.05) self.anim += Animation(x=200, y=600, duration=.05) & Animation( size=(500, 500), duration=.05) self.anim += Animation(x=5, y=300, duration=.05) & Animation( size=(200, 200), duration=.05) self.anim += Animation(x=600, y=10, duration=.05) & Animation( size=(10, 10), duration=.05) self.anim += Animation(x=400, y=75, duration=2.) & Animation( size=(120, 120), duration=2.) self.anim.start(self.ids.animation)
class JoyScreen(Screen): joystick = Joystick(0, False) X_axis = ObjectProperty(0.0) Y_axis = ObjectProperty(0.0) def __init__(self, **kwargs): Builder.load_file('joyScreen') super(JoyScreen, self).__init__(**kwargs) def switch_text2(self): list = [1] if self.joystick.button_combo_check(list)==1: self.lbz.text = "" self.lb0.text = "Ready" self.xy.color = 0, 1, 0, 1 if self.joystick.get_button_state(0) == 0: self.lb0.text = "Ready" self.xy.color = 0, 1, 0, 1 else: self.lb0.text = "" self.xy.color = 1, 0, 0, 1 self.counter() else: self.lbz.text = "Hold 2" self.lb0.text = "" self.xy.color = 1, 1, 1, 1 def joystick_thread(self): while 1: self.joystick.refresh() self.X_axis = self.joystick.get_axis('x') * Window.size[0] * 1/2 self.Y_axis = self.joystick.get_axis('y') * Window.size[1] * 1/2 # self.switch_text() self.switch_text2() sleep(1/200) # print(self.X_axis) def start_joystick_thread(self): Thread(target=self.joystick_thread).start() def transition_back(self): """ Transition back to the main screen :return: """ SCREEN_MANAGER.current = MAIN_SCREEN_NAME global xin xin = 0 global x def counter(self): global xin global x xin = xin + 1 if xin == 1000: xin = 0 else: print ("%d" % xin) x = "%d" % xin random.seed(x) Window.clearcolor = (random.random(), random.random(), random.random(), 1000)