For this lab, you are going to move most of your code from move.py
into a class CS104Scribbler and encapsulate information about the Scribbler into that class.
lab13
Folder, etc.S:\workspace
. Make a lab13
folder. lab11
's move.py
file, then ***copy*** the move.py
file over from your lab11
folder into your lab13
folder. Otherwise, you may get my move.py
file from our CS104 course moodle page. Copy it to your lab13
folder.move.py
file to cs104scrib.py
.CS104Scribbler
classWe are going to make a new class CS104Scribbler
that is a subclass of Scribbler
, a class provided by the myro
module that we've been using all semester. To do this, do these steps:
cs104scrib.py
file that imports the scribpoint
module. We won't use scribpoint
anymore.cs104scrib.py
still must import the myro
module.CENTS_PER_SEC
, etc.) write a line of code to create the CS104Scribbler
class definition, make this new class a subclass of Scribbler
, the class provided by myro
.CS104Scribbler
class.CS104Scribbler
class), add self
as the first parameter.self.
to the front. E.g., where it says turnRight(1, time)
make it say self.turnRight(1, time)
Next, we need to add a constructor for CS104Scribbler
:
__init__
). The constructor should take 5 parameters: self
, comport
, x
, y
, and angle
. These should be optional parameters, with default values: the default value for comport
should be "COM40"
; the default values for x
, y
, and angle
, should all be 0.self
and comport
. I've shown you how to do this in your notes from class. x
, y
, and angle
in self
. Put the underscore character at the beginning of the attribute names (e.g., _x
)getX(), getY(), getAngle(), setX(), setY(), and setAngle()
.The goToPoint method previously took two parameters, both of them being ScribPoint
objects. Now, the CS104Scribbler
class stores its current x
, y
, and angle
of the Scribbler robot, so a call to goToPoint
does not need to pass in the first parameter -- where the Scribbler robot currently is on the whiteboard. Also, we don't need a ScribPoint
class anymore -- we can just pass in the x and y coordinates for where the scribbler robot should move to.
goToPoint()
to goTo()
.self
, newX
, and newY
.self._x
and self._y
as the "from" point and newX
and newY
as the "to" point.self._x
and self._y
. Because you are writing code that is in the class, you can use self._x
and self._y
directly, or, you can call self.setX(newValue)
, etc. lab13.py
. At the top of the file, put from cs104scrib import *
. (cs104scrib.py
will import myro
, so you don't have to do that anymore.)CS104Scribbler
object. The first parameter to the constructor is optional -- the comport
. If you connect with "COM40"
, you don't have to pass in any argument in the constructor call. Make sure you store the result in a variable called scrib
. This is your CS104Scribbler
object.CS104Scribbler
constructor makes a call to the superclass Scribbler()
constructor. That constructor will do the init("COM40")
call for us. That is why we pass in the comport and we don't call init()
ourselves like we've been doing all semester. goTo(10, 10)
.goTo(10, -10)
.goTo(-10, -10)
.goTo(0, 0)
.The robot still turns to face east after every move. This is dumb. We can store the angle
the robot is facing in the CS104Scribbler
object, and then the code can figure out how to turn to get to the next point it needs to go to.
goTo()
that makes the robot turn back to face east after it has traveled forward.self._angle.
So, now we will store the angle the robot used to get from the previous point to the current point, and we'll leave the robot facing that angle.atan2()
assumes the robot is facing east -- and there is nothing we can do about that. So, after calling that code and figuring out the angle the robot needs to turn to (assuming the robot is facing east), we need to change the result, based on which angle the robot is already facing. To do this, subtract from the computed angle the current angle the robot is facing. That result is passed to the call to self.turnDegrees()
.At the end of lab11
I give you the points necessary to draw a 5-point star. Look in that lab to get those points. Implement this again in your lab13.py
main code.
Note: you are done with the lab. But, notice that we really didn't finish our cs104scrib.py
code. We really should fix travelForw()
, travelBack()
, turnLeftDegrees()
, and turnRightDegrees()
so that they each store the current x, y, and angle of the robot. If we changed those, we wouldn't have to make the changes we did to goTo()
. But, we'll just leave the code as it is, for now...
lab13.py
that isn't relevant anymore (old print statements, etc.) Make sure your code is well-documented, indented, hospitable, etc. Make sure you have the correct information in it about you, the author.To submit your final version of lab13.py
and cs104scrib.py
, you’ll need to use Windows Explorer.
lab13.py
and cs104scrib.py
files down in your lab13
folder.lab13.py
and cs104scrib.py
.T:\CS104\current\<yourid>\
.lab13
. (Do NOT call it Lab13
or lab 13
or Lab 13
or ISawMommaKissingSantaClaus
. Call it lab13
.)lab13
? If not, drop and give me 50 push-ups, and then rename the folder lab13
.lab13.py
and cs104scrib.py
) into that folder.Grading Rubric: 15 points total
10 points: program that runs correctly. There are many parts to handle in this program, so make sure all work correctly.
1 points: correct comments at the top of the file.
4 points: code is clean and neat and uses good comments and variable names. I.e., the code is hospitable.