Skip to content

Commit

Permalink
sets: Add Audi Xbox example.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Feb 16, 2024
1 parent 9ccd119 commit faaacce
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ video:
youtube: "c0KVNdJlAkc"
description: "Control the Technic Audi RS Q e-tron with the Powered Up Remote."
code: "#program"
building_instructions:
external: https://www.lego.com/cdn/product-assets/product.bi.core.pdf/6508358.pdf
---

In this project we'll show you how to control the Audi RS Q e-tron with the Powered Up remote.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions sets/technic/42160-audi-rs-q-e-tron/xbox-controller/audi_blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pybricks blocks file:{"blocks":{"languageVersion":0,"blocks":[{"type":"blockGlobalSetup","id":"bjK,wS1MYO7aiYkFSwd{","x":254,"y":17,"deletable":false,"next":{"block":{"type":"variables_set_motor","id":"g??RF]?65}mDL*lODRv`","fields":{"VAR":{"id":"Sfkt5!a|mBRd)veW}%@V"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"|^1Nfd(Dhq5-aHpPbK8(","fields":{"NAME":"A"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":".{{l7YMM6{J=2P$%DL}~","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"{s*h:+G,8yg8gJ~,~22#","fields":{"VAR":{"id":"VeQJ3bN/NZ@%t]W;@|j0"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"/wf]Q3.hq(|?BbXDYFxy","fields":{"NAME":"B"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"oT;4{l#}-P{P+YWsua[V","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_motor","id":"/5/4E([a|w*HXH3lCeZ1","fields":{"VAR":{"id":"g4h(Hwe2rwZ;t+I3jn}-"}},"inputs":{"PORT":{"shadow":{"type":"blockParametersPort","id":"]M-5kmKcDnx$UGMu-3Nr","fields":{"NAME":"D"}}},"POSITIVE_DIRECTION":{"shadow":{"type":"blockParametersDirection","id":"*$Utn7SALQwJcW0gvs{g","fields":{"SELECTION":"Direction.CLOCKWISE"}}}},"next":{"block":{"type":"variables_set_car","id":"7D9,d+uH1$jJcu/L|.{R","extraState":{"optionLevel":1},"fields":{"VAR":{"id":"N?o:_)gI%v:qMoTdDK3}"}},"inputs":{"VAR":{"shadow":{"type":"variables_get_motor_device","id":"eih^k6;{Y:2},r/h9j;C","fields":{"VAR":{"id":"g4h(Hwe2rwZ;t+I3jn}-","name":"steer","type":"Motor"}}}},"VAR2":{"shadow":{"type":"variables_get_motor_device","id":"ZTl,ay[tn5`#UT;r:]iI","fields":{"VAR":{"id":"Sfkt5!a|mBRd)veW}%@V","name":"front","type":"Motor"}}}},"DRIVE1":{"shadow":{"type":"variables_get_motor_device","id":"Ga45HDGU4T`=MJLb`X|s","fields":{"VAR":{"id":"VeQJ3bN/NZ@%t]W;@|j0","name":"rear","type":"Motor"}}}}},"next":{"block":{"type":"variables_set_xbox_controller","id":"s+_^IwVdquWW*)1{jXc2","fields":{"VAR":{"id":"jO|qF()?HGJCju9#H|@j"}}}}}}}}}}}}},{"type":"blockGlobalStart","id":"3tJe|AWl0baN(wH9a$@.","x":252,"y":363,"deletable":false,"next":{"block":{"type":"blockFlowWhile","id":"VoVB}x{TNVKlM$2,bw4@","fields":{"MODE":"WHILE"},"inputs":{"BOOL":{"shadow":{"type":"blockLogicTrue","id":"BomU1(Vt;1T,#9Ll{diM"}},"DO":{"block":{"type":"blockCarDrive","id":"lgIQ`%W,O@d;1qGX*h_b","extraState":{"optionLevel":1},"fields":{"METHOD":"CAR_DRIVE_AT_POWER"},"inputs":{"VAR":{"shadow":{"type":"variables_get_car_device","id":"V`Y45418lIx03ytU24V]","fields":{"VAR":{"id":"N?o:_)gI%v:qMoTdDK3}","name":"car","type":"Car"}}}},"ARG0":{"shadow":{"type":"unit_percent","id":"qP{0iwt,H{]#fVY.!2+F","fields":{"VALUE0":50}},"block":{"type":"blockMathArithmetic","id":";|~g{SR=:PQ9N~]-oLE;","fields":{"OP":"MINUS"},"inputs":{"A":{"shadow":{"type":"blockMathNumber","id":"9t`X6Iq4$;G#@iTg1kAf","fields":{"NUM":1}},"block":{"type":"blockJoystickValue","id":"KCe/~Igl{lOj]y;|:zPN","fields":{"JOYSTICK":"XBOX_RT"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"rWy^~aM-oK3#%QMo9@)]","fields":{"VAR":{"id":"jO|qF()?HGJCju9#H|@j","name":"controller","type":"XboxController"}}}}}}},"B":{"shadow":{"type":"blockMathNumber","id":",ZJeGu5j/is]w/-j?v-k","fields":{"NUM":1}},"block":{"type":"blockJoystickValue","id":"}At`)tGf$m,y^=UIgKgc","fields":{"JOYSTICK":"XBOX_LT"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"JMyX.NUun;_JSNfS]F[h","fields":{"VAR":{"id":"jO|qF()?HGJCju9#H|@j","name":"controller","type":"XboxController"}}}}}}}}}}},"next":{"block":{"type":"blockCarSteer","id":"LK2khVSl+b:M_i(-avdQ","inputs":{"VAR":{"shadow":{"type":"variables_get_car_device","id":"RTR?tH8|$cNc4]c2QHNW","fields":{"VAR":{"id":"N?o:_)gI%v:qMoTdDK3}","name":"car","type":"Car"}}}},"VALUE0":{"shadow":{"type":"unit_percent","id":"I!FN])%J6VvXfJW$XlwZ","fields":{"VALUE0":0}},"block":{"type":"blockJoystickValue","id":"D;Q0R#_CDosKVXX%c[`6","fields":{"JOYSTICK":"XBOX_LJ_X"},"inputs":{"VAR":{"shadow":{"type":"variables_get_gamepad","id":"8up=nR.TaMD5=P@5R2?}","fields":{"VAR":{"id":"jO|qF()?HGJCju9#H|@j","name":"controller","type":"XboxController"}}}}}}}}}}}}}}}}]},"variables":[{"name":"red","id":"FzD$8|dNe|B#-2+Y.hdQ","type":"ColorDef"},{"name":"orange","id":"{of6uF9-$%Ft6U1VDf[Q","type":"ColorDef"},{"name":"yellow","id":"aKr)5Gf-6htFP?X%sbBO","type":"ColorDef"},{"name":"green","id":"WuP|e8`f=qfAVRiq19f2","type":"ColorDef"},{"name":"cyan","id":"}XXP6~EkM]eIFloyy2{d","type":"ColorDef"},{"name":"blue","id":"GxK}gQ$dvFo8D5[;mUiO","type":"ColorDef"},{"name":"violet","id":"WO-ukRlm7I.O6CxS~5(5","type":"ColorDef"},{"name":"magenta","id":"7%6im3e@o~v3Yf1Z9G81","type":"ColorDef"},{"name":"white","id":"/)?+7F;=2eSALN@0F)84","type":"ColorDef"},{"name":"none","id":"atL7YEXxu:k_%tXHmWx[","type":"ColorDef"},{"name":"car","id":"N?o:_)gI%v:qMoTdDK3}","type":"Car"},{"name":"controller","id":"jO|qF()?HGJCju9#H|@j","type":"XboxController"},{"name":"front","id":"Sfkt5!a|mBRd)veW}%@V","type":"Motor"},{"name":"rear","id":"VeQJ3bN/NZ@%t]W;@|j0","type":"Motor"},{"name":"steer","id":"g4h(Hwe2rwZ;t+I3jn}-","type":"Motor"}]}
from pybricks.iodevices import XboxController
from pybricks.parameters import Direction, Port
from pybricks.pupdevices import Motor
from pybricks.robotics import Car

# Set up all devices.
front = Motor(Port.A, Direction.CLOCKWISE)
rear = Motor(Port.B, Direction.CLOCKWISE)
steer = Motor(Port.D, Direction.CLOCKWISE)
car = Car(steer, [front, rear])
controller = XboxController()


# The main program starts here.
while True:
car.drive_power(controller.triggers()[1] - controller.triggers()[0])
car.steer(controller.joystick_left()[0])
23 changes: 23 additions & 0 deletions sets/technic/42160-audi-rs-q-e-tron/xbox-controller/audi_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pybricks.iodevices import XboxController
from pybricks.parameters import Direction, Port
from pybricks.pupdevices import Motor
from pybricks.robotics import Car

# Set up all devices.
front = Motor(Port.A, Direction.CLOCKWISE)
rear = Motor(Port.B, Direction.CLOCKWISE)
steer = Motor(Port.D, Direction.CLOCKWISE)
car = Car(steer, [front, rear])
controller = XboxController()


# The main program starts here.
while True:

# Drive using the trigger inputs.
brake, acceleration = controller.triggers()
car.drive_power(acceleration - brake)

# Steer with the left joystick.
horizontal, vertical = controller.joystick_left()
car.steer(horizontal)
40 changes: 40 additions & 0 deletions sets/technic/42160-audi-rs-q-e-tron/xbox-controller/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: "Xbox Controller"
maintainer:
user: "pybricks"
name: "The Pybricks Team"
image:
local: "./audi-xbox.jpg"
description: "Control the Technic Audi RS Q e-tron with the Xbox Controller."
code: "#python-program"
building_instructions:
external: https://www.lego.com/cdn/product-assets/product.bi.core.pdf/6508358.pdf
video:
youtube: "fxInp9cutNg"
---

In this project we'll show you how to control the Audi RS Q e-tron with the
Xbox Controller, using either block programming or Python.

Be sure to check out the documentation in the Pybricks app for instructions
to pair the controller with the hub.

Note: This is brand a new feature. Try it with [Pybricks beta](https://beta.pybricks.com/)!

# Block Program

You can easily code this with the new block coding feature. Just drag and drop
the blocks as shown below, or download the ready-made project here. In
Pybricks, just go to the file menu and click the "Import a file" icon to open
it.

<a href="./audi_blocks.py" target="_blank" class="btn btn--primary"><i class="fas fa-puzzle-piece"></i>&nbsp;&nbsp;Download block program</a>

![Xbox Block Program](audi-xbox-program.png)

# Python Program

{% include copy-code.html %}
```python
{% include_relative audi_python.py %}
```

0 comments on commit faaacce

Please sign in to comment.