0% found this document useful (0 votes)
26 views49 pages

CPE313 Week2

The document outlines a Week 2 lecture for a Robotics Technology course, focusing on using VEXcode VR to program a VR Robot to navigate a playground. It details learning objectives related to drivetrain commands, error handling in Python, and tasks for students to complete involving robot movement and turning. Additionally, it emphasizes the importance of planning and behavior in programming the robot's actions to achieve specific goals.

Uploaded by

sccbos31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views49 pages

CPE313 Week2

The document outlines a Week 2 lecture for a Robotics Technology course, focusing on using VEXcode VR to program a VR Robot to navigate a playground. It details learning objectives related to drivetrain commands, error handling in Python, and tasks for students to complete involving robot movement and turning. Additionally, it emphasizes the importance of planning and behavior in programming the robot's actions to achieve specific goals.

Uploaded by

sccbos31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Duration: 120 min Lecture: Week 2 Learners: UG 3rd year Course Code: CPE313

Robotics Technology
Dr. Mohannad Farag

2021-2022, Semester I
Lesson overview

You will learn how to use VR code to make the VR Robot utilize the Drivetrain commands in order to move around the
Castle Crasher Playground.

Learning objectives

1. Identify how to use the [Drive for] command to drive the VR Robot a specific distance.
2. Identify how to use the [Set drive velocity] command to set the speed of the
drivetrain.
3. Identify how to use the [Turn for] command to turn the VR Robot right or left.
4. Identify how to use the [Turn to heading] and [Drive to rotation] command to turn the
VR Robot to a given heading/ rotation.
5. Identify the relation between the code Planning and robot Behavior.

Keywords

Encoder, rotation, velocity, linear motion, rotational


motion
Python Code & Error Handling
Technical Implementation Details - Project Help - VR Python
VEXcode VR uses a modified version of Python runtime called Pyodide* to support Python
programming in browsers.

VEXcode VR supports many of the Python 3.8 Standard library features.

For mor info:


https://kb.vex.com/hc/en-us/articles/360044206011-Technical-Implementation-Details-Project-Help-VR-Python

_______________________________________________________________________

*Pyodide: Bringing the scientific Python stack to the browser


https://vr.vex.com/
Vex code Editor Interface
Monitor, Counsel & Help
Open the Challenge 1 code
Try to remove one bracket
Syntax error
Syntax error
Fix it back
Try to remove the indentation of the “for” loop
Indentation error
Indentation Error
Fix it back (press tab)
Try to remove the “e”: driv
Attribute Error
Attribute Error
Fix it back
Try to remove the “n”: drivetrai
Name Error
Name Error
Fix it back
Python 3.10 is released
Better Error Messages

https://betterprogramming.pub/python-3-10-is-released-know-whats-new-and-if-it-s-worth-the-switch-19c7a5738f7c
Drivetrain Move Forward/ Reverse
How can the brain sense the wheel’s rotation?

Clawbot Drivetrain Movement "Boss" is a modified Chevy Tahoe that is


designed to drive autonomously
Rotary Encoder

https://www.youtube.com/watch?v=v4BbSzJ-hz4&list=RDCMUCmkP178NasnhR3TWQyyP4Gw&start_radio=1&rv=v4BbSzJ-hz4&t=36
Rotary Encoder
How Rotary Encoder Works
Encoder Circuit connection
Encoder Example code
The direct proportional relationship between the motor and wheels rotations
and the robot linear movement.

For example…
If the motor spins 2 times…
• Then the wheels spin 2 times…
• And the robot travels the circumference of the wheel, 2 times!
These proportional relationships are affected by any slipping or sticking of the
wheels and the surface the robot is driving on.

Slower movements allow the wheels to grip and Faster speeds may cause wheels to slip and come
move forward the entirety of the distance up short of the intended distance
Task 1: Motors Forward/ Reverse Instructions
1. Create a New Text Project
2. Rename it: week2.task1
3. Open Castle Crasher playground
4. Try it!
5. Change the distance to 500 mm
6. Monitor the distance sensor value
7. Try to crash the center castle.
8. Let the robot move back to its
start position.
9. Set the robot speed to 100%.
10. Submit your code to MS teams
Drivetrain Turning
Robot turning approximately 90 degrees to the right
Does velocity affect the margin of error?
Rotational Movement
• Rotational movement occurs when an object follows along a curved path.

• When your robot makes a turn, it is using rotational movement, and torque to make that
turn. Torque is known as a twisting force that causes rotations.
Inertial Sensor

• The Inertial Sensor is built with a combination


of a 3-axis (X, Y, and Z) accelerometer and a 3-
axis gyroscope. The accelerometer will detect a
change in motion (acceleration) in any
direction and the gyroscope electronically
maintains a reference position so it can
measure a rotational change of position in any
direction against this reference.
Inertial Sensor
• The built-in combination of the
accelerometer and gyroscope in one
sensor allows for effective and accurate
navigation, as well as, controlling any
change in the motion of a robot.

• A detection of a change in motion can


help decrease the chance of a robot falling
over when it is driving or while it is
climbing over an obstacle.
When your robot turns, it is following the circumference of a circle.

Circumference of turn Diameter of robot


Calculate to find # of Motor Rotations
• Keep in mind that the formula for calculating
circumference is:

c = π * d.

Where; c = circumference, d = diameter = track


width.
Calculate to find # of Motor Rotations
• The arc length can be found for any number
of degree turns by using the following
formula:

Arc length = (degrees / 360) * c

• Using the arc length, you can find the number


of motor rotations using the formula:

Motor rotations = arc length / wheel


circumference
Try It: Calculate to find # of Motor Rotations
• Use the same mathematical process to
calculate how many times the motor rotates
during a 135-degree turn, if the wheel
diameter is 50 mm and the robot width is
133 mm.
Turn for vs Turn to heading vs Turn to rotation
• Use the HELP function to figure it out!
Task 2: Turn for vs Turn to heading vs Turn to rotation
1. Create a New Text Project
2. Rename it: week2.task2
3. Open Castle Crasher playground
4. Use turn for command to crash
the bottom left castle
5. Use turn to heading command to
crash the bottom left castle
6. Use turn to rotation command to
crash the bottom left castle
7. What is the difference?
8. Submit your code to MS teams
Planning and Behaviors

Big behavior Small behaviors


Planning and Behaviors
• As a programmer, your primary responsibilities are:

• First, to formulate a plan for the robot to reach the


goal.

• And then, translate that plan into a program that the


robot can follow.

• The plan will simply be the sequence of behaviors


the robot needs to follow, and the program will just
be those behaviors translated into the programming
language.
Week 2 Challenge 1: Castle Crasher Robot

1. Watch the solution video

2. Create a New Text Project

3. Rename it: week2.Challenge1

4. Use Drivetrain commands to knock over


all buildings on the Castle
Crasher Playground.

5. Submit your code to MS teams

Video Link

You might also like