The lecture discusses driving autonomous vehicles and covers:
1. The hardware components of the RACECAR including its Intel RealSense camera, depth camera, and LIDAR sensor.
2. How the sensors measure distance and their limitations.
3. Controlling the RACECAR using modules like drive and controller to set speed, angle, and respond to button inputs.
4. Programming paradigms like global variables and start/update functions for the RACECAR code.
6. Hardware Components
● Intel RealSense Camera -
○ Functions like a normal camera where the lens are able to
take color images.
○ Functions as a depth camera.
■ Camera uses software to compute the distance of each
pixel in an image
6
8. LIDAR
● Short for Light and Radar
● Similar to depth camera, LIDAR computes the
distance of points surrounding the RACECAR.
8
9. How does it work?
● Emits a laser and records the time it takes for the laster to
bounce back to find distance.
● Capable of rotating many times per second and able to update
the distance of all objects in all directions of the plane.
● Cannot detect objects above or below its view.
9
13. The Start-Update Paradigm
● start()
○ Function that is called once at the start of the code
○ Used for setup (Initial conditions)
● update()
○ Equivalent to an infinite while loop
○ Runs at a clock speed of ~60Hz, but may be slower due to
calculations done inside function
○ Has no memory! Do not save data inside this function!
13
14. Global Variables
● scope
○ Describes all locations where a variable can be accessed
○ If a variable is used inside of a function, it cannot be used outside
of a function!
● global
○ Keyword that allows variables to be accessed from everywhere
14
15. Why is this important?
● Variables used in the update() function are not saved!
● Memory allocated to the garbage collector (python only) after it has
been run, similar to erasing the function’s memory
● To “save” our data after a single instance, use a global variable
1. Create the global variable in the setup() function
2. Edit the variable in the update() function
3. Contents of the variable are now saved for later use!
15
16. Code Analysis
1. As time goes on, what happens to the value of variable foo?
2. What happens if we omit the global keyword from the start() function?
3. Why do we not need the global keyword to access foo from the bar()
function?
16
17. The Drive Module
● Most important function!
○ rc.drive.set_speed_angle(speed, angle)
● rc: The racecar object
● drive: A module inside the racecar library
● set_speed_angle: A function inside the drive module
● speed: Abstract value for speed of car (-1 to 1)
● angle: Abstract value for angle of car (-1 to 1)
17
18. The Drive Module
● speed: Abstract value for speed of car (-1 to 1)
○ -1 = Drive Backwards
○ 0 = Stop Moving
○ 1 = Drive Forwards
● angle: Abstract value for angle of car (-1 to 1)
○ -1 = Turn the wheels left
○ 0 = Turn the wheels straight
○ 1 = Turn the wheels right
18
19. More Modules
● rc.get_delta_time()
○ Returns the time in seconds since the last time the update()
function was called
● rc.drive.stop()
○ Stops the car in place (speed 0, angle 0)
19
21. The Controller Module
● rc.controller.Button.A
● rc.controller.Button.B
● rc.controller.Button.X
● rc.controller.Button.Y
● rc.controller.Button.RB (The right bumper)
● rc.controller.Button.LB (The left bumper)
● rc.controller.Button.LJOY (The Left Joystick button)
● rc.controller.Button.RJOY (The Right Joystick button)
21
22. The Controller Module
● Toggleable buttons
○ A, B, C, D (1, 2, 3, 4 on keyboard)
● Binary Values
○ 0 or 1 only! Pressed or not pressed
● rc.controller.is_down(button)
○ Returns true for every frame that the button is down
● rc.controller.was_pressed(button)
○ Returns true for the first time that the button is down
● rc.controller.was_released(button)
○ Returns true the frame after the button is no longer being pressed
22
23. The Controller Module
● Left and Right Triggers
○ Control Car Speed
○ 0 or 1 only! Pressed or not pressed
● rc.controller.get_trigger(trigger)
○ Returns the value (from 0-1) of the trigger
23
24. The Controller Module
● Left and Right Joystick
○ Joysticks have 2 axes, the x and y
○ Ranges from -1 to 1, where
■ -1 = left/down, 0 = center, and 1 = right/up
● rc.controller.get_joystick(joystick)
○ Returns the (x,y) value of the joystick
24
25. Code Analysis
1. What buttons on the controller are used in this script?
2. Where does the variable speed get its definition from?
3. What does the script do?
25
27. Let’s Double Check our Setup
● Open terminal. If you’re on windows type bash and press enter.
● Type racecar test and press enter
27
28. Run demo.py
1. Open up the racecar sim and press Begin Simulation (demo
level should be selected in the drop down menu)
2. Go back into your bash terminal and type “racecar cd” and
press enter
3. Then type ls
28
32. Jupyter Notebooks have space for
code and text
● Think like google collab, you can have text boxes with
instructions, or explanations of your code, and boxes with
runnable python code
○ Textboxes are called “markdowns”
○ Python boxes are “code”
32
33. Kernel
● The kernel is the “engine” of your code
● When you open a notebook document the associated kernel is
automatically launched
● When the notebook is executed, the kernel performs all the
computations
33
36. Text Formatting in markdown
● Use # to create a title
● Use ** to bold
● Use * to italicize
● To create a new line, press the spacebar twice before hitting
enter
36
40. Data Structures
● What is the purpose of data structures?
○ Store data in an organized manner
○ Establish a relationship between data points
● Why do we use data structures in our code?
○ Improve data retrieval algorithms
○ Organize data using sorting methods
○ Carry out a program operation
40
41. Direct Data Structures
● Arrays (C family, Java)
○ Immutable memory
○ Allocation of memory within hardware registers
● Python List
○ Mutable storage component
○ Flexible data types
● Python Dictionary
○ Hyper-flexible data storage
○ Cross-platform capability with JSON file type
41
42. Abstract Data Structures
● What is the purpose of abstract data?
● How is one piece of data related to another?
● How do we take data out of the structure?
● How is data organized within the structure?
● Why do we use ADTs?
42
43. Abstract Data Structures
● Linked List
○ Focuses on sequences of data
○ Each data “item” is connected to the next via a link
○ Can take out any item at any location via algorithm
● Queue
○ A “tunnel” of data
○ Can extract data only from the beginning and the end
● Stack
○ Think of it as a stack of cards
○ Can only take a card (data) from the top of the deck
43
44. Linked Lists
● Simple Linked List: Items travel forward only
● Double Linked List: Items travel both forwards and backwards
● Circular Linked List: Last item points back to the first item
Double Linked List
44
Circular Linked List
45. Linked Lists
● Insertion: Add an element to the beginning of a list
● Deletion: Delete an element at the end of a list
● Display: Display the complete list
● Search: Given a key, find an element in the list
● Delete: Given a key, remove an element from the list
45
Linked List Insertion
46. Queues
● FIFO structure (First In, First Out)
○ Visualize this as a one-way tunnel of data
○ “Nodes” only contain the data
○ The first node must be the first to leave the queue
○ The final node must be the final node to leave the queue
FIFO Queue
46
47. Queues
● Extremely important applications:
○ Process Management
○ Task Management
● If you have multiple tasks inside a queue, which task is
performed first? Which task is performed last?
FIFO Queue
47
48. Queues
48
● What operation is being
performed in the
following sequence of
events?
● How does this follow the
queue structure?
● How is this implemented
within the code?
49. Queues
49
● What operation is being performed in the following sequence of
events?
● How does this follow the queue structure?
● How is this implemented within the code?
50. Stack
50
● LIFO structure (Last In, First Out)
○ Visualize this as a stack of cards / stack of paper
○ “Nodes” only contain the data
○ The first node must be the last node to leave the queue
○ The final node must be the first node to leave the queue
LIFO Stack
51. Stack
51
● Some Applications of stacks
○ Operation Evaluation: RPN Solving
○ Function Calls: How does the compiler know to keep track
of function locations within the code?
LIFO Stack
52. Implementation of ADTs
52
● All ADTs can be represented as a algorithmically modified
version of a direct data type in Python!
○ Python Classes -> Linked List
○ Python List -> FIFO Queue
○ Python List -> Lifo Stack
56. Lab 1 Tasks
1. When the A button is pressed, drive in a circle.
2. When the B button is pressed, drive in a square
3. When the X button is pressed, drive in a figure-eight
4. When the Y button is pressed, drive in any shape of your choice
Keep in mind that all these buttons must work in a single script!
Hint: Use global variables and look at demo.py for an example!
56
57. Lab 1 Tips
1. Watch out for racecar acceleration! The first side of a square may not
contain the same movement script as the second side of the square.
2. How do we organize code in a script with multiple reused operations
such as in this lab? How can we make our overall code neater?
3. How can we use data structures and the relationship between data
points to provide the RACECAR with varying movements?
4. You may have to apply guess and check (quite a lot). Be patient! We’re
here to help if you need it!
57
58. Demo Environment Challenges
Make a copy of Lab1.py (call it Lab1challenge.py for example) and write some code to
solve the following problem statements (This is done in the MISC Level):
1. Write a script to make the racecar drive backwards into the wall of bricks in the
demo simulation when the B button is pressed. Stop the car when it and the wall
collides.
2. Write a script to make the racecar drive in an “S” shape through the 3 intro cones
without touching any of them. Drive the car up the ramp and stop the script right
before the car falls off the edge. Make the racecar perform this task when the X
button has been pressed. (You can program another button to drive the car off
the ramp and crash into the pyramid of bricks if you want)
58