File tree 3 files changed +27
-27
lines changed 3 files changed +27
-27
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class AuxiliaryHelp(object):
19
19
# Initialize the object
20
20
def __init__ (self ):
21
21
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." )
23
23
exit (1 )
24
24
self ._instances .append (self )
25
25
@@ -32,13 +32,13 @@ def cleanup (self):
32
32
#-------------------------------------------------------------------------------
33
33
#write a value to a log file
34
34
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 ()
Original file line number Diff line number Diff line change 3
3
import motorcontrol , servocontrol , sonarcontrol , auxiliary
4
4
import time
5
5
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
-
19
6
#-------------------------------------------------------------------------------
20
7
# Setting direction (finding the longest way without obstacles
21
8
22
- def findWay (self ):
9
+ def findWay ():
23
10
distanceArray = []
24
11
25
12
#pan left
@@ -55,7 +42,7 @@ def findWay(self):
55
42
del distanceArray [:]
56
43
57
44
#-------------------------------------------------------------------------------
58
- def move (self ):
45
+ def move ():
59
46
while sonar .distance ()>= 10 :
60
47
motor .forward ()
61
48
print ("moving forward" )
@@ -69,6 +56,19 @@ def move(self):
69
56
print ("resetting position" )
70
57
#-------------------------------------------------------------------------------
71
58
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
+
72
72
try :
73
73
while True :
74
74
findWay ()
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class SonarControl(object):
32
32
# Initialize the object
33
33
def __init__ (self ):
34
34
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." )
36
36
exit (1 )
37
37
self ._instances .append (self )
38
38
You can’t perform that action at this time.
0 commit comments