Hello, I am desperate for help! #2092
Replies: 2 comments 3 replies
-
Thanks for moving your question over here. Much easier to answer this way 😄 If you're new to this, I highly recommend trying out a few small programs without the remote first. Such as this one. Use the menu on the left/top to learn more about installing and running programs if you haven't already installed it. Once you're familiar with running programs, you can try programs with the Xbox Controller too. Coincidentally, user @corticalstack kindly shared an example just the other day.
Running with the controller also involves some coding (or copying examples). You can basically configure what each of the buttons/sticks will do for your robot --- as opposed to a conventional single-function RC toy. That said, since this is starting to become a popular request, we should probably also add some ready-made examples for the advanced driving base to our introductory guide. |
Beta Was this translation helpful? Give feedback.
-
I just needed to get started with the pybricks guide, get to understand the purpose of the different block types, and looked at another example shared by another user. Here's my block layout that works GREAT with the Prime advanced chassis build and xbox controller. And the associated python, which you can upload into pybricks: # pybricks blocks file:{"blocks":{"languageVersion":0,"blocks":[{"type":"blockGlobalSetup","id":"bjK,wS1MYO7aiYkFSwd{","x":150,"y":100,"deletable":false,"next":{"block":{"type":"variables_set_prime_hub","id":"c3S,+`%AUqD|%VsO.}^f","extraState":{"optionLevel":1},"fields":{"VAR":{"id":"Ofx7sc@uiX,6.@kBiF1s"}},"inputs":{"AXIS_TOP":{"shadow":{"type":"blockParametersAxis","id":"t0V(jC7H_|-3#.cRK}D^","fields":{"VALUE":"z"}}},"AXIS_FRONT":{"shadow":{"type":"blockParametersAxis","id":"M|8C9]?%aq6~t%LeEP(W","fields":{"VALUE":"x"}}}},"next":{"block":{"type":"variables_set_motor","id":"s3;M67x:I2n4^VH9qUe7","fields":{"VAR":{"id":"M,mzTd}4U=byiUfKC.QB"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"o*JM[@MI.kwbhd0;u2y{","fields":{"NAME":"A"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"if}8LiChn_J%K)Z`6uM+","fields":{"SELECTION":"Direction.COUNTERCLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"D[v5:9({=bX{n]ZK.,-$","fields":{"VAR":{"id":"{O+MdF7kl3})3`69XB~@"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"5GIwBO|T={LmH[pvEO*f","fields":{"NAME":"E"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"FX3PTc4hV8#c}rb)f*]Y","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_drive_base","id":",?mt0/hW=2{.7vngxa3T","fields":{"VAR":{"id":"#Fj,0b}.iR8Xw`6yDp^/"}},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"uer-[cj4H-_.o/jcjuaN","fields":{"VAR":{"id":"M,mzTd}4U=byiUfKC.QB","name":"leftmotor","type":"Motor"}}}},"VAR2":{"shadow":{"type":"variables_get_motor_device","id":"g:UGHy$Y,L#k|:42sYPo","fields":{"VAR":{"id":"{O+MdF7kl3})3`69XB~@","name":"rightmotor","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_distance","id":"2y!hR^M-]GGC,b?z^M(f","fields":{"VALUE0":88}}},"VALUE1":{"shadow":{"type":"unit_distance","id":";8)nc;+te5O.wK7/xi!Q","fields":{"VALUE0":144}}}},"next":{"block":{"type":"variables_set_motor","id":"yt@CH4i^jkdimt#*kpc:","fields":{"VAR":{"id":"qhG`g)~*Q?Qi|F@spQXp"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"u0LJ}|IwGSCdvUu#)qII","fields":{"NAME":"D"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"BAl0-|plkVCT=^h|iTm/","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"=;^PyW}NP}U0WIgK=|a2","fields":{"VAR":{"id":"Pzp5v]7iE-`+#[}b^D7y"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"Rjt6]Ei78rWhfZ#@#HTo","fields":{"NAME":"C"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"vD|VT+!H^YL?{7}jbm:+","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_xbox_controller","id":"F7qP.)gz3hi.|rHUhiv(","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW"}},"next":{"block":{"type":"variables_setup_any","id":"P~uN66$cl~Na$wB0]TSs","fields":{"VAR":{"id":"f:`slIhP329)7X+SLhe@"}},"inputs":{"VALUE0":{"shadow":{"type":"blockMathNumber","id":"da%@y-eAvyurv7OYloj+","fields":{"NUM":1}}}}}}}}}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"3tJe|AWl0baN(wH9a$@.","x":155,"y":637,"deletable":false,"next":{"block":{"type":"blockFlowWhile","id":"KNyC}54I6bXjeZg6`D_(","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"qmQUH#j_*+rvxc)FfPFM"}},"DO":{"block":{"type":"blockIfElse","id":"$@*fS4VgMJC}I1*[y4}Q","extraState":{"optionLevel":1},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"Owiap@F;8{R`keM2c8OH"},"block":{"type":"blockVariableGetValue","id":"Nl)).^?PEP-qnIQDMrx=","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"%@0mF[ioTgxpQ%#Y$_tW","fields":{"VAR":{"id":"f:`slIhP329)7X+SLhe@","name":"drive","type":"Any"}}}}}}},"DO0":{"block":{"type":"blockLightMatrixDo","id":"~I1uPvHj3+[UI~9XsG*t","extraState":{"optionLevel":2},"fields":{"METHOD":"LIGHT_MATRIX_SYMBOL"},"inputs":{"VAR":{"shadow":{"type":"variables_get_light_matrix_hub","id":"H-d~P}yjY`N.y34%MxFe","fields":{"VAR":{"id":"Ofx7sc@uiX,6.@kBiF1s","name":"prime hub","type":"PrimeHub"}}}},"ARG0":{"shadow":{"type":"text","id":"SDe~Rt3~a;J|:Xf)rZFN","fields":{"TEXT":"D"}}}},"next":{"block":{"type":"blockMotorStop","id":"uLU~yn6hlvDck-f6GTjY","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"U|FPb/}!lA,Wg,54{24e","fields":{"VAR":{"id":"Pzp5v]7iE-`+#[}b^D7y","name":"bumper","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"LWS2l.iS=aVVpjLCRAnq","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockMotorStop","id":"*G_qcX8jOj.O(.Wzo)R,","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"YKC3FXB;#O|px:C-F#OE","fields":{"VAR":{"id":"qhG`g)~*Q?Qi|F@spQXp","name":"pickup","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"IT*?wY3L:V8#}wa%HX~T","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockDriveBaseDrive","id":"gW%rk}c4|b1tg#a+!/3i","extraState":{"optionLevel":1},"fields":{"METHOD":"DRIVEBASE_DRIVE_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_drive_base_device","id":"|x8[Cx{ieBIh/I%-0}dz","fields":{"VAR":{"id":"#Fj,0b}.iR8Xw`6yDp^/","name":"drive base","type":"DriveBase"}}}},"ARG0":{"shadow":{"type":"unit_speed","id":"O8p=!Re[99yZb`Q=UHOG","fields":{"VALUE0":2}},"block":{"type":"blockMathArithmetic","id":"ry*AJ#T2x(|R3vq36];-","fields":{"OP":"MULTIPLY"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":",3+.th#nfMsjpFkfgteU","fields":{"NUM":4}}},"B":{"shadow":{"type":"blockMathNumber","id":"OL`)[email protected]|jaF|R[","fields":{"NUM":1}},"block":{"type":"blockJoystickValue","id":";Y/=nV6tXF9_z^ZMx;j0","fields":{"JOYSTICK":"XBOX_LJ_Y"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"[{HyW;)DoI%E3}psWN*l","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW","name":"xbox","type":"XboxController"}}}}}}}}}},"ARG1":{"shadow":{"type":"unit_angularVelocity","id":"oMb6W5p6]D`0oP:*0Q/p","fields":{"VALUE0":0}},"block":{"type":"blockJoystickValue","id":"8~2[tI;)SThdZbV@Q(Vw","fields":{"JOYSTICK":"XBOX_RJ_X"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"W3YnX0@gcp!RolE7W!xd","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW","name":"xbox","type":"XboxController"}}}}}}}}}}}}}}}},"ELSE":{"block":{"type":"blockLightMatrixDo","id":"(f:NrkL^^k/bj:.*DX^?","extraState":{"optionLevel":2},"fields":{"METHOD":"LIGHT_MATRIX_SYMBOL"},"inputs":{"VAR":{"shadow":{"type":"variables_get_light_matrix_hub","id":"mO1z:XI=fp[2Hm64q*Rm","fields":{"VAR":{"id":"Ofx7sc@uiX,6.@kBiF1s","name":"prime hub","type":"PrimeHub"}}}},"ARG0":{"shadow":{"type":"text","id":"/m?pr5hbRWav92,x(4pk","fields":{"TEXT":"T"}}}},"next":{"block":{"type":"blockMotorStop","id":"s+1s)}}T]^LhIx+}O@w$","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"S9JuE6*Bs5rZ/WbKd:H+","fields":{"VAR":{"id":"M,mzTd}4U=byiUfKC.QB","name":"leftmotor","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"ASp1d(0AVGc)~W6kB;C4","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockMotorStop","id":"}1!)S:!f~In9Y{!Gc`_9","inputs":{"VAR":{"shadow":{"type":"variables_get_simple_motor_device","id":"W=^~[U.lA2C^l,+sQrz$","fields":{"VAR":{"id":"{O+MdF7kl3})3`69XB~@","name":"rightmotor","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"parameters_stop_3","id":"xFTz6O04*A{ZBT5+D?oL","fields":{"VALUE":"Stop.COAST"}}}},"next":{"block":{"type":"blockMotorRun","id":"x.G99;hQ[9{m#b22XEr|","extraState":{"optionLevel":0},"fields":{"METHOD":"MOTOR_RUN_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"i1eL*A=]b%?Pv:FFE.TE","fields":{"VAR":{"id":"qhG`g)~*Q?Qi|F@spQXp","name":"pickup","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"kew*h-HZqR|@AqT|x{8=","fields":{"VALUE0":500}},"block":{"type":"blockMathArithmetic","id":"uSatdPp*Q;zidX@|Z1,T","fields":{"OP":"MULTIPLY"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"2!0,v)Kxi_n=AwPL;@-=","fields":{"NUM":2}}},"B":{"shadow":{"type":"blockMathNumber","id":"OL`)[email protected]|jaF|R[","fields":{"NUM":1}},"block":{"type":"blockJoystickValue","id":"C:3P|Lv@LZCehItpqpm_","fields":{"JOYSTICK":"XBOX_LJ_Y"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"v|V_WlpLR8B20Tb^J#DR","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW","name":"xbox","type":"XboxController"}}}}}}}}}}},"next":{"block":{"type":"blockMotorRun","id":"8EJVhpBjf~oc)~ga}62]","extraState":{"optionLevel":0},"fields":{"METHOD":"MOTOR_RUN_FOREVER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"OQz4Zvhv[J/!)I1|J|].","fields":{"VAR":{"id":"Pzp5v]7iE-`+#[}b^D7y","name":"bumper","type":"Motor"}}}},"VALUE0":{"shadow":{"type":"unit_angularVelocity","id":"kew*h-HZqR|@AqT|x{8=","fields":{"VALUE0":500}},"block":{"type":"blockMathArithmetic","id":"5RgAtgc#e3a{/x-c4/pm","fields":{"OP":"MULTIPLY"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"W[=(QaBc!TlHOEu$9fjN","fields":{"NUM":2}}},"B":{"shadow":{"type":"blockMathNumber","id":"OL`)[email protected]|jaF|R[","fields":{"NUM":1}},"block":{"type":"blockJoystickValue","id":"!UIzMo$jXT~`ioD8Gbx!","fields":{"JOYSTICK":"XBOX_RJ_Y"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"#4`~4s+qOFN_]][4ykDV","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW","name":"xbox","type":"XboxController"}}}}}}}}}}}}}}}}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"Z:CZ$wBNxkya:IM:~ip-","x":1207,"y":110,"next":{"block":{"type":"blockFlowWhile","id":",:ib(Eu2r/6ID9g/HjgI","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"Uscd4B!0Vu0Sni-;RG_V"}},"DO":{"block":{"type":"blockWaitUntil","id":")ENwEeBDJ)O%/=VF_6h_","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"w^ze-6MSe)RO!.{KA~$$"},"block":{"type":"blockButtonIsPressed","id":"yOmOQA*XbhhY.ND$I)}s","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"=S=/d1%qUSwID}w*Q-GU","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW","name":"xbox","type":"XboxController"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"8}+bRSI=!,XaOu/)Yu_z","fields":{"VALUE":"Y"}}}}}}},"next":{"block":{"type":"blockIfElse","id":"DeZ@x8+_aZoOy+5LYbXr","extraState":{"optionLevel":1},"inputs":{"IF0":{"shadow":{"type":"blockLogicTrue","id":"g5,-vrP=%pX$,;nH.HVj"},"block":{"type":"blockVariableGetValue","id":"@]xjR|u$s_(I=#XETBg[","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"A0!v8AzM1EARUxRK/Cr]","fields":{"VAR":{"id":"f:`slIhP329)7X+SLhe@","name":"drive","type":"Any"}}}}}}},"DO0":{"block":{"type":"blockVariableSetValue","id":"lOn?ph4jfL{uob0}qD83","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"Z@8X{ZLl}QiO+Nm;50%;","fields":{"VAR":{"id":"f:`slIhP329)7X+SLhe@","name":"drive","type":"Any"}}}},"VALUE0":{"shadow":{"type":"blockMathNumber","id":"kz;5Qz)Y5~r%0aLvb??H","fields":{"NUM":0}}}}}},"ELSE":{"block":{"type":"blockVariableSetValue","id":"LE,7)O1*;X3H{/bv@a}H","inputs":{"VAR":{"shadow":{"type":"variables_get_any","id":"O2Xk$w8?adMlBKX%c.4I","fields":{"VAR":{"id":"f:`slIhP329)7X+SLhe@","name":"drive","type":"Any"}}}},"VALUE0":{"shadow":{"type":"blockMathNumber","id":"F]jE8S5i!IzrN{z/x-^O","fields":{"NUM":1}}}}}}},"next":{"block":{"type":"blockWaitUntil","id":"l_*8N=K62yVKGg;AH_l@","inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"0#`P+x.3xP(MkCT8Hp/^"},"block":{"type":"blockLogicIsNone","id":"X~q`8ywdk,pkC)4v=*|(","fields":{"OP":"NOT"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"!Ij{4FL4;`R=FLmu/r~o"},"block":{"type":"blockButtonIsPressed","id":"LXbl,oLty3I1*7-XJ9{d","inputs":{"VAR":{"shadow":{"type":"variables_get_keypad","id":"+P#CPuj!1|nM!0hl-Fp@","fields":{"VAR":{"id":")XlK1fmo~TOjc3hl_;hW","name":"xbox","type":"XboxController"}}}},"VALUE0":{"shadow":{"type":"blockParametersButton","id":"L`+@)f!=8qA~FTQeL,fH","fields":{"VALUE":"Y"}}}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"red","id":"WYiCsSzGMPoD85-6Bfub","type":"ColorDef"},{"name":"orange","id":"GbCKJ_^Ft3FpgC.R$M/^","type":"ColorDef"},{"name":"yellow","id":"wK}H[i5Vtf,//5=44O,o","type":"ColorDef"},{"name":"green","id":"%fppVC0W8p*o+L5w]TG~","type":"ColorDef"},{"name":"cyan","id":"SLvjAZ.WnANSV3Qp)f4t","type":"ColorDef"},{"name":"blue","id":"tmXH%w5%1s+Q$A,^fzMQ","type":"ColorDef"},{"name":"violet","id":"31Lb9~(?-FN{4C{n9Rgm","type":"ColorDef"},{"name":"magenta","id":"?}jh_O50h+)7Zs)Aw.cJ","type":"ColorDef"},{"name":"white","id":"dvT3%37=xp0WVJg.+4F$","type":"ColorDef"},{"name":"none","id":"::%3f`.+qLRYSQ@5j=lu","type":"ColorDef"},{"name":"prime hub","id":"Ofx7sc@uiX,6.@kBiF1s","type":"PrimeHub"},{"name":"drive base","id":"#Fj,0b}.iR8Xw`6yDp^/","type":"DriveBase"},{"name":"drive","id":"f:`slIhP329)7X+SLhe@","type":"Any"},{"name":"xbox","id":")XlK1fmo~TOjc3hl_;hW","type":"XboxController"},{"name":"leftmotor","id":"M,mzTd}4U=byiUfKC.QB","type":"Motor"},{"name":"rightmotor","id":"{O+MdF7kl3})3`69XB~@","type":"Motor"},{"name":"pickup","id":"qhG`g)~*Q?Qi|F@spQXp","type":"Motor"},{"name":"bumper","id":"Pzp5v]7iE-`+#[}b^D7y","type":"Motor"}],"info":{"type":"pybricks","version":"1.2.3"}}
from pybricks.hubs import PrimeHub
from pybricks.iodevices import XboxController
from pybricks.parameters import Axis, Button, Direction, Port, Stop
from pybricks.pupdevices import Motor
from pybricks.robotics import DriveBase
from pybricks.tools import multitask, run_task, wait
# Set up all devices.
prime_hub = PrimeHub(top_side=Axis.Z, front_side=Axis.X)
leftmotor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
rightmotor = Motor(Port.E, Direction.CLOCKWISE)
drive_base = DriveBase(leftmotor, rightmotor, 88, 144)
pickup = Motor(Port.D, Direction.CLOCKWISE)
bumper = Motor(Port.C, Direction.CLOCKWISE)
xbox = XboxController()
# Initialize variables.
drive = 1
async def main1():
global drive
while True:
await wait(1)
while not Button.Y in xbox.buttons.pressed():
await wait(1)
if drive:
drive = 0
else:
drive = 1
while Button.Y in xbox.buttons.pressed():
await wait(1)
async def main2():
while True:
await wait(1)
if drive:
prime_hub.display.char('D')
bumper.stop()
pickup.stop()
drive_base.drive(4 * xbox.joystick_left()[1], xbox.joystick_right()[0])
else:
prime_hub.display.char('T')
leftmotor.stop()
rightmotor.stop()
pickup.run(2 * xbox.joystick_left()[1])
bumper.run(2 * xbox.joystick_right()[1])
async def main():
await multitask(main1(), main2())
run_task(main()) |
Beta Was this translation helpful? Give feedback.
-
Guys, I have a spike prime advanced driving base, and I cant figure how to connect it and run it with an xbox controller. I see the step by step guides for coding, but I can make it run with the controller. I have no idea what I am doing, can somebody assist me on a step by step as If I where an 8 year old? Please? thank you!
Beta Was this translation helpful? Give feedback.
All reactions