This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.v5python
executable file
·1 lines (1 loc) · 11.4 KB
/
controller.v5python
1
{"mode":"Text","textContent":"\n# -----------------------------------------------------------\n# _____ _ _ _ _ _ \n# / __ \\ | | | | (_) | | | \n# | / \\/_ __ ___ __ _| |_ ___ __| | __ ___| |_| |__ \n# | | | '__/ _ \\/ _` | __/ _ \\/ _` | \\ \\ /\\ / / | __| '_ \\ \n# | \\__/\\ | | __/ (_| | || __/ (_| | \\ V V /| | |_| | | | \n# \\____/_| \\___|\\__,_|\\__\\___|\\__,_| \\_/\\_/ |_|\\__|_| |_| \n \n# _ _ _____ _ \n# | | | | | ___| | | \n# | |_| |__ ___ __ _ |___ \\ _ __ __ _ ___| | _____ _ __ \n# | __| '_ \\ / _ \\ \\ \\ / / \\ \\ | '_ \\ / _` |/ __| |/ / _ \\ '__|\n# | |_| | | | __/ \\ V / /\\__/ / | |_) | (_| | (__| < __/ | \n# \\__|_| |_|\\___| \\_/ \\____/ | .__/ \\__,_|\\___|_|\\_\\___|_| \n# | | \n# |_| \n# -----------------------------------------------------------\n\n\n\n\n\n\n\n\n\n\n\n\n#!base C:\\Users\\void\\Documents\\example.v5python\n#!out C:\\Users\\void\\Documents\\controller.v5python\n# !dump partial.py\n# stores func call perams\nclass partial:\n def __init__(self, func, *args, **kwargs):\n self.args = args\n self.kwargs = kwargs\n self.func = func\n def __call__(self):\n self.func(*self.args, **self.kwargs)\n\n\n\n\n\n\n# !dump listView.py\nclass listView:\n def __init__(self, data=None) -> None:\n self.data = [] if data is None else data\n def set(self, a, b):\n i=0\n for c in (self.data):\n if c[0] == a:\n self.data[i] = (a,b)\n i+=1\n def get(self, a):\n for c in self.data:\n if c[0] == a:\n return c[1]\n\n\n\n\n#!ignoreNextLine\n#from partial import partial\nfrom vex import *\n#!ignoreNextLine\n#controller_1 = Controller(PRIMARY)\n#!ignoreNextLine\n#motor_1 = Motor(Ports.PORT1, 1, False)\n#!ignoreNextLine\n#motor_2 = Motor(Ports.PORT2, 1, False)\n#!ignoreNextLine\n#motor_3 = Motor(Ports.PORT3, 1, False)\n#!ignoreNextLine\n#motor_4 = Motor(Ports.PORT4, 1, False)\n#!ignoreNextLine\n#motor_5 = Motor(Ports.PORT5, 1, False)\n#!ignoreNextLine\n#motor_6 = Motor(Ports.PORT5, 1, False)\n\n#!ignoreNextLine\n#brain=Brain()\n\n\n\n\n\nMoterStuff = listView([\n (\"#1\", False),\n (\"#2\", False),\n (\"#3\", False),\n (\"#4\", False),\n (\"#5\", False),\n (\"#6\", False),\n ])\n\nMenu = [\n ('Invert direction', False),\n ('Invert turning', False),\n (\"Invert shoot\", False),\n (\"Conv speed\", 7),\n ('Turn coefficient', 2),\n (\"Moter directions\", MoterStuff)\n ]\n\ndef moter_fix(val, index):\n return val if MoterStuff.data[index][-1] else -val\n\n\n# !dump controllerScreen.py\n#!ignoreNextLine\n###controller_1 = Controller(PRIMARY)\n\n\n\n\nclass Screen:\n def __init__(self) -> None:\n self.scrollPos = 0\n self.baseList = listView(Menu)\n self.currenList = self.baseList\n\n def render(self):\n controller_1.screen.clear_screen()\n controller_1.screen.set_cursor(0, 0)\n controller_1.screen.print(\"-->\")\n lvi = list(self.currenList.data)\n for c in range(3):\n citemI = (self.scrollPos+c)\n if len(lvi) > citemI:\n citem = lvi[citemI]\n controller_1.screen.print(citem[0])\n controller_1.screen.print(\": \")\n \n if type(citem[1]) is not type(Screen.left) and type(citem[1]) is not listView:\n controller_1.screen.print(str(citem[1]))\n controller_1.screen.next_row()\n def changeScroll(self, off):\n self.scrollPos = self.scrollPos+off\n if len(list(self.currenList.data)) == self.scrollPos:\n self.scrollPos = self.scrollPos-1\n elif -1 == self.scrollPos:\n self.scrollPos = 0\n self.render()\n def left(self):\n lvi = list(self.currenList.data)\n citem = lvi[self.scrollPos]\n if len(lvi) > self.scrollPos:\n if type(citem[1]) is int or type(citem[1]) is float:\n self.currenList.set(citem[0], citem[1]-1)\n elif type(citem[1]) is bool:\n self.currenList.set(citem[0], False)\n elif type(citem[1]) is type(Screen.left):\n citem[1]()\n elif type(citem[1]) is listView:\n self.currenList = citem[1]\n self.scrollPos = 0\n self.render()\n def right(self):\n lvi = list(self.currenList.data)\n citem = lvi[self.scrollPos]\n if len(lvi) > self.scrollPos:\n if type(citem[1]) is int or type(citem[1]) is float:\n self.currenList.set(citem[0], citem[1]+1)\n elif type(citem[1]) is bool:\n self.currenList.set(citem[0], True)\n elif type(citem[1]) is type(Screen.left):\n citem[1]()\n elif type(citem[1]) is listView:\n self.currenList = citem[1]\n self.scrollPos = 0\n\n self.render()\n def b(self):\n self.currenList = self.baseList\n self.render()\n\n\n\ndef driver(*args): \n m1 = controller_1.axis3.position() - (controller_1.axis4.position()/screen.baseList.get(\"Turn coefficient\"))\n m2 = controller_1.axis3.position() + (controller_1.axis4.position()/screen.baseList.get(\"Turn coefficient\"))\n if screen.baseList.get(\"Invert direction\"):\n m1=-m1\n m2=-m2\n if screen.baseList.get(\"Invert turning\"):\n m3 = m1\n m1=m2\n m2=m3\n motor_1.set_velocity(moter_fix(m1, 0) , PERCENT)\n motor_2.set_velocity(moter_fix(m2, 1) , PERCENT)\n motor_1.spin(FORWARD)\n motor_2.spin(FORWARD)\n # print(controller_1.axis4.position())\n\ndef conv_belt(*args):\n speed = controller_1.axis2.position()\n\n motor_3.set_velocity(moter_fix(speed, 2) * screen.baseList.get(\"Conv speed\") / 10 , PERCENT)\n motor_3.spin(FORWARD)\n\n# trigRot = 0\n# def spin360():\n# global trigRot\n# trigRot+=moter_fix(360, 3)\n# motor_4.spin_to_position(trigRot, DEGREES)\nfireDir = True\ndef fire(*args):\n global fireDir\n \n if fireDir:\n # global fireDir\n fireDir=False\n motor_4.set_velocity(moter_fix(100, 3))\n motor_5.set_velocity(moter_fix(100, 4))\n # wait(1.5, SECONDS)\n motor_6.set_velocity(moter_fix(20 , 5))\n\n \n else:\n # global fireDir\n fireDir=True\n motor_4.set_velocity(0)\n motor_5.set_velocity(0)\n motor_6.set_velocity(0)\n motor_4.spin(REVERSE if screen.baseList.get(\"Invert shoot\") else FORWARD )\n motor_5.spin(REVERSE if screen.baseList.get(\"Invert shoot\") else FORWARD )\n motor_6.spin(REVERSE if screen.baseList.get(\"Invert shoot\") else FORWARD )\n\n\ndef pre_autonomous():\n # actions to do when the program starts\n wait(1, SECONDS)\n\ndef autonomous():\n brain.screen.clear_screen()\n brain.screen.print(\"autonomous code\")\n\nscreen = None\ndef user_control():\n global screen\n brain.screen.clear_screen()\n # !dump controllerBindings.py\n\n screen = Screen()\n screen.render()\n controller_1.buttonUp.pressed(lambda: screen.changeScroll(-1))\n controller_1.buttonDown.pressed(lambda: screen.changeScroll(1))\n controller_1.buttonLeft.pressed(lambda: screen.left())\n controller_1.buttonRight.pressed(lambda: screen.right())\n\n controller_1.buttonB.pressed(lambda: screen.b())\n\n\n\n\n\n\n\n ###############\n\n\n\n controller_1.axis3.changed(driver)\n controller_1.axis4.changed(driver)\n\n controller_1.axis2.changed(conv_belt)\n\n controller_1.buttonR2.pressed(fire)\n # controller_1.buttonR2.pressed(spin360)\n\n\n\n# create competition instance\ncomp = Competition(user_control, autonomous)\npre_autonomous()\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","textLanguage":"python","rconfig":[{"port":[],"name":"controller_1","customName":false,"deviceType":"Controller","deviceClass":"controller","setting":{"left":"","leftDir":"false","right":"","rightDir":"false","upDown":"","upDownDir":"false","xB":"","xBDir":"false","drive":"none","id":"primary"},"triportSourcePort":22},{"port":[1],"name":"motor_1","customName":false,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"},"triportSourcePort":22},{"port":[2],"name":"motor_2","customName":false,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"},"triportSourcePort":22},{"port":[3],"name":"motor_3","customName":false,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"},"triportSourcePort":22},{"port":[4],"name":"motor_4","customName":false,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio36_1"},"triportSourcePort":22},{"port":[5],"name":"motor_5","customName":false,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"},"triportSourcePort":22},{"port":[11],"name":"vision_11","customName":false,"deviceType":"Vision","deviceClass":"vision","setting":{"config":"{\"config\":{\"brightness\":50,\"signatures\":[{\"name\":\"BLUE_\",\"parameters\":{\"uMin\":579,\"uMax\":929,\"uMean\":754,\"vMin\":-527,\"vMax\":-127,\"vMean\":-326,\"rgb\":6774877,\"type\":0,\"name\":\"BLUE_\"},\"range\":2.1},{\"name\":\"RED_\",\"parameters\":{\"uMin\":9401,\"uMax\":9831,\"uMean\":9616,\"vMin\":-2791,\"vMax\":-2629,\"vMean\":-2710,\"rgb\":12934464,\"type\":0,\"name\":\"RED_\"},\"range\":8.9},{\"name\":\"R2\",\"parameters\":{\"uMin\":0,\"uMax\":0,\"uMean\":0,\"vMin\":0,\"vMax\":0,\"vMean\":0,\"rgb\":0,\"type\":0,\"name\":\"R2\"},\"range\":3},{\"name\":\"SIG_4\",\"parameters\":{\"uMin\":0,\"uMax\":0,\"uMean\":0,\"vMin\":0,\"vMax\":0,\"vMean\":0,\"rgb\":0,\"type\":0,\"name\":\"SIG_4\"},\"range\":2.5},{\"name\":\"SIG_5\",\"parameters\":{\"uMin\":0,\"uMax\":0,\"uMean\":0,\"vMin\":0,\"vMax\":0,\"vMean\":0,\"rgb\":0,\"type\":0,\"name\":\"SIG_5\"},\"range\":2.5},{\"name\":\"SIG_6\",\"parameters\":{\"uMin\":0,\"uMax\":0,\"uMean\":0,\"vMin\":0,\"vMax\":0,\"vMean\":0,\"rgb\":0,\"type\":0,\"name\":\"SIG_6\"},\"range\":2.5},{\"name\":\"SIG_7\",\"parameters\":{\"uMin\":0,\"uMax\":0,\"uMean\":0,\"vMin\":0,\"vMax\":0,\"vMean\":0,\"rgb\":0,\"type\":0,\"name\":\"SIG_7\"},\"range\":2.5}],\"codes\":[]}}","isConfigured":"false"},"triportSourcePort":22},{"port":[6],"name":"motor_6","customName":false,"deviceType":"Motor","deviceClass":"motor","setting":{"reversed":"false","fwd":"forward","rev":"reverse","gear":"ratio18_1","id":"partner"},"triportSourcePort":22}],"slot":0,"platform":"V5","sdkVersion":"20220726.10.00.00","appVersion":"3.0.4","minVersion":"3.0.0","fileFormat":"1.2.0","icon":"","targetBrainGen":"First","v5Sounds":[{"name":"game over","url":"static/sounds/mixkit-arcade-retro-game-over-213.wav"}],"v5SoundsEnabled":false,"target":"Physical"}