SlideShare a Scribd company logo
1 of 59
Download to read offline
Lecture 3 - Driving
MIT BWSI
Autonomous RACECAR Course
Presented By: Chris Lai & Paul Thai
1
Welcome Back!
2
Code Clash #5 has begun. Good Luck!
3
Sensors and Control Flow
How does the robot know where to go?
Outlook of the Vehicle
5
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
Depth Camera and Color Camera
7
LIDAR
● Short for Light and Radar
● Similar to depth camera, LIDAR computes the
distance of points surrounding the RACECAR.
8
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
Image
10
Questions
● Why do we need two sensors to measure
distance?
● What do you think are the limitations of both
sensors?
11
RACECAR Libraries & Modules
Specific to RACECAR!
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
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
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
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
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
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
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
Controlling the Racecar
20
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
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
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
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
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
Running Scripts in the Sim
From VSC to the .exe!
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
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
29
4. Type “racecar sim demo.py” into your terminal
5. Start the program from the sim
30
Jupyter Notebooks
A review from PLYMI
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
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
34
35
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
37
Creating a Jupyter Notebook
1. Go into VSC
2. Create new file (with the extension .ipynb)
3. Select Jupyter Notebook
38
Data Structures
How do we store and manage data?
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
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
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
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
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
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
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
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
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?
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?
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
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
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
Queue Implementation in Python
53
Stack Implementation in Python
54
Lab 1: Driving in Shapes
Let’s draw some shapes!
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
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
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
See you all tomorrow!
59

More Related Content

Similar to Lecture 3 - Driving.pdf

Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!zynamics GmbH
 
Distributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflowDistributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflowEmanuel Di Nardo
 
Dfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshopDfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshopTamas K Lengyel
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdfAyushKumar93531
 
How to build TiDB
How to build TiDBHow to build TiDB
How to build TiDBPingCAP
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developersbennuttall
 
Shop 2 presentation slide
Shop 2 presentation slideShop 2 presentation slide
Shop 2 presentation slideAndrea Tucci
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyPriyanka Aash
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
The Volcano/Cascades Optimizer
The Volcano/Cascades OptimizerThe Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer宇 傅
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Golinuxlab_conf
 
Hadoop and cassandra
Hadoop and cassandraHadoop and cassandra
Hadoop and cassandraChristina Yu
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptxnikshaikh786
 
Industrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder LogicIndustrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder LogicRobocraze
 
Feature engineering pipelines
Feature engineering pipelinesFeature engineering pipelines
Feature engineering pipelinesRamesh Sampath
 
Computer Architecture and Organization
Computer Architecture and OrganizationComputer Architecture and Organization
Computer Architecture and Organizationssuserdfc773
 

Similar to Lecture 3 - Driving.pdf (20)

Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!
 
Web dynpro
Web dynproWeb dynpro
Web dynpro
 
Distributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflowDistributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflow
 
Dfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshopDfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshop
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdf
 
How to build TiDB
How to build TiDBHow to build TiDB
How to build TiDB
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
 
Esd module2
Esd module2Esd module2
Esd module2
 
Shop 2 presentation slide
Shop 2 presentation slideShop 2 presentation slide
Shop 2 presentation slide
 
Sayeh basic computer
Sayeh basic computerSayeh basic computer
Sayeh basic computer
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
The Volcano/Cascades Optimizer
The Volcano/Cascades OptimizerThe Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Go
 
Hadoop and cassandra
Hadoop and cassandraHadoop and cassandra
Hadoop and cassandra
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptx
 
Industrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder LogicIndustrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder Logic
 
Feature engineering pipelines
Feature engineering pipelinesFeature engineering pipelines
Feature engineering pipelines
 
Computer Architecture and Organization
Computer Architecture and OrganizationComputer Architecture and Organization
Computer Architecture and Organization
 

Recently uploaded

Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!AutoScandia
 
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...shivangimorya083
 
Hyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai Motor Group
 
How To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation IssueHow To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation IssueTerry Sayther Automotive
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...amitlee9823
 
Chapter-1.3-Four-Basic-Computer-periods.pptx
Chapter-1.3-Four-Basic-Computer-periods.pptxChapter-1.3-Four-Basic-Computer-periods.pptx
Chapter-1.3-Four-Basic-Computer-periods.pptxAnjieVillarba1
 
9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay NagarGenuineGirls
 
John deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualJohn deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualExcavator
 
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...amitlee9823
 
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdfJohn Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdfExcavator
 
design a four cylinder internal combustion engine
design a four cylinder internal combustion enginedesign a four cylinder internal combustion engine
design a four cylinder internal combustion enginepiyushsingh943161
 
Tata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataTata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataaritradey27234
 
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办ezgenuh
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Delhi Call girls
 
John Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair ManualJohn Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair ManualExcavator
 
Call me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home DeliveryCall me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home DeliveryPooja Nehwal
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...amitlee9823
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Delhi Call girls
 

Recently uploaded (20)

Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
 
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class  Service 100% Saf...
Hot Modals Call Girls (Delhi) Dwarka9711199171✔️ High Class Service 100% Saf...
 
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
 
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
 
Hyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRC
 
How To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation IssueHow To Fix Mercedes Benz Anti-Theft Protection Activation Issue
How To Fix Mercedes Benz Anti-Theft Protection Activation Issue
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
 
Chapter-1.3-Four-Basic-Computer-periods.pptx
Chapter-1.3-Four-Basic-Computer-periods.pptxChapter-1.3-Four-Basic-Computer-periods.pptx
Chapter-1.3-Four-Basic-Computer-periods.pptx
 
9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar
 
John deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualJohn deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance Manual
 
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
Bangalore Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore E...
 
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdfJohn Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
John Deere 7430 7530 Tractors Diagnostic Service Manual W.pdf
 
design a four cylinder internal combustion engine
design a four cylinder internal combustion enginedesign a four cylinder internal combustion engine
design a four cylinder internal combustion engine
 
Tata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataTata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tata
 
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
一比一原版(UdeM学位证书)蒙特利尔大学毕业证学历认证怎样办
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
 
John Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair ManualJohn Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair Manual
 
Call me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home DeliveryCall me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
Call me @ 9892124323 Call Girl in Andheri East With Free Home Delivery
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
 

Lecture 3 - Driving.pdf

  • 1. Lecture 3 - Driving MIT BWSI Autonomous RACECAR Course Presented By: Chris Lai & Paul Thai 1
  • 3. Code Clash #5 has begun. Good Luck! 3
  • 4. Sensors and Control Flow How does the robot know where to go?
  • 5. Outlook of the Vehicle 5
  • 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
  • 7. Depth Camera and Color Camera 7
  • 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
  • 11. Questions ● Why do we need two sensors to measure distance? ● What do you think are the limitations of both sensors? 11
  • 12. RACECAR Libraries & Modules Specific to RACECAR!
  • 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
  • 26. Running Scripts in the Sim From VSC to the .exe!
  • 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
  • 29. 29
  • 30. 4. Type “racecar sim demo.py” into your terminal 5. Start the program from the sim 30
  • 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
  • 34. 34
  • 35. 35
  • 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
  • 37. 37
  • 38. Creating a Jupyter Notebook 1. Go into VSC 2. Create new file (with the extension .ipynb) 3. Select Jupyter Notebook 38
  • 39. Data Structures How do we store and manage data?
  • 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
  • 55. Lab 1: Driving in Shapes Let’s draw some shapes!
  • 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
  • 59. See you all tomorrow! 59