Skip to content

Commit 5121eb1

Browse files
Nathan LamNathan Lam
Nathan Lam
authored and
Nathan Lam
committed
2to3 python
1 parent 0cbc9c5 commit 5121eb1

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

auxiliary.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AuxiliaryHelp(object):
1919
# Initialize the object
2020
def __init__(self):
2121
if ( len(self._instances)>1 ):
22-
print "ERROR: One instance of AuxiliaryHelp is running already."
22+
print("ERROR: One instance of AuxiliaryHelp is running already.")
2323
exit(1)
2424
self._instances.append(self)
2525

@@ -32,13 +32,13 @@ def cleanup (self):
3232
#-------------------------------------------------------------------------------
3333
#write a value to a log file
3434
def writetofile (self,label,value):
35-
logfile = 'logfile.txt'
36-
mystring = label+': '+str(value)+'\n'
37-
try:
38-
f=open(logfile, 'a')
39-
f.write(mystring)
40-
print 'Wrote the following to '+logfile+':\n'+label+': '+str(value)+'\n'
41-
f.close()
42-
except IOError:
43-
print("cannot find file: " + logfile)
44-
exit()
35+
logfile = 'logfile.txt'
36+
mystring = label+': '+str(value)+'\n'
37+
try:
38+
f=open(logfile, 'a')
39+
f.write(mystring)
40+
print('Wrote the following to '+logfile+':\n'+label+': '+str(value)+'\n')
41+
f.close()
42+
except IOError:
43+
print("cannot find file: " + logfile)
44+
exit()

main.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,10 @@
33
import motorcontrol, servocontrol, sonarcontrol, auxiliary
44
import time
55

6-
#instantiate objects
7-
motor = motorcontrol.MotorControl()
8-
servo = servocontrol.ServoControl()
9-
sonar = sonarcontrol.SonarControl()
10-
aux = auxiliary.AuxiliaryHelp()
11-
12-
#center servos
13-
servo.pancenter()
14-
servo.tiltcenter()
15-
16-
#start logging data
17-
aux.writetofile('Servos are dead center', 0)
18-
196
#-------------------------------------------------------------------------------
207
# Setting direction (finding the longest way without obstacles
218

22-
def findWay(self):
9+
def findWay():
2310
distanceArray = []
2411

2512
#pan left
@@ -55,7 +42,7 @@ def findWay(self):
5542
del distanceArray[:]
5643

5744
#-------------------------------------------------------------------------------
58-
def move(self):
45+
def move():
5946
while sonar.distance()>=10:
6047
motor.forward()
6148
print("moving forward")
@@ -69,6 +56,19 @@ def move(self):
6956
print("resetting position")
7057
#-------------------------------------------------------------------------------
7158

59+
#instantiate objects
60+
motor = motorcontrol.MotorControl()
61+
servo = servocontrol.ServoControl()
62+
sonar = sonarcontrol.SonarControl()
63+
aux = auxiliary.AuxiliaryHelp()
64+
65+
#center servos
66+
servo.pancenter()
67+
servo.tiltcenter()
68+
69+
#start logging data
70+
aux.writetofile('Servos are dead center', 0)
71+
7272
try:
7373
while True:
7474
findWay()

sonarcontrol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SonarControl(object):
3232
# Initialize the object
3333
def __init__(self):
3434
if ( len(self._instances)>1 ):
35-
print "ERROR: One instance of SonarControl is running already."
35+
print("ERROR: One instance of SonarControl is running already.")
3636
exit(1)
3737
self._instances.append(self)
3838

0 commit comments

Comments
 (0)