14 Connecting to NXT brick and creating motor object, sensor object 15 and so on. Motor encoders will be reset. 20 self.
sock = nxt.locator.find_one_brick()
23 Motor(self.
sock, PORT_B),
24 Motor(self.
sock, PORT_C)]
27 Sound(self.
sock, PORT_2),
28 Light(self.
sock, PORT_3),
29 Ultrasonic(self.
sock, PORT_4)]
34 Finalizing connection with NXT brick. 40 Resetting encoders of NXT motors 43 m.reset_position(relative)
47 This operation receives array and set them as motor power. If the 48 number of vels items does not match with the number of motors, 49 smaller number of them will be taken and set respectively. 51 for i, v
in enumerate(vels[:min(len(vels),len(self.
motors))]):
57 Getting motors' angle (degrees) 64 stat = m.get_tacho().tacho_count
72 print "Unknown motor encoder error" 73 print sys.exc_info()[1]
81 Getting sensors' values. Data will be returned as array. 95 print "Unknown sensor error" 96 print sys.exc_info()[1]
104 It gives appropriate values to motors, and angles of motors are 105 obtained and shown. Sensor data are also obtained and shown. 107 if __name__ ==
"__main__":
114 nxt.setMotors([80,-80,80])
116 mstat = nxt.getMotors()
117 for i, m
in enumerate(mstat):
118 print "(" , i,
"): ", m
120 nxt.setMotors([0,0,0])
124 sensors = [
"Touch",
"Sound",
"Light",
"USonic"]
125 sval = nxt.getSensors()
def setMotors(self, vels)
def __init__(self, bsock=None)
def resetPosition(self, relative=0)