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().connect()
23 Motor(self.
sock, PORT_B),
24 Motor(self.
sock, PORT_C)]
27 SoundSensor(self.
sock, PORT_2),
28 LightSensor(self.
sock, PORT_3),
29 UltrasonicSensor(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))]):
52 self.
motors[i].power = max(min(v,127),-127)
53 self.
motors[i].mode = MODE_MOTOR_ON | MODE_REGULATED
54 self.
motors[i].regulation_mode = REGULATION_MOTOR_SYNC
55 self.
motors[i].run_state = RUN_STATE_RUNNING
56 self.
motors[i].tacho_limit = 0
57 self.
motors[i].set_output_state()
61 Getting motors' angle (degrees) 68 stat = m.get_output_state()
76 print "Unknown motor encoder error" 77 print sys.exc_info()[1]
85 Getting sensors' values. Data will be returned as array. 99 print "Unknown sensor error" 100 print sys.exc_info()[1]
108 It gives appropriate values to motors, and angles of motors are 109 obtained and shown. Sensor data are also obtained and shown. 111 if __name__ ==
"__main__":
118 nxt.setMotors([80,-80,80])
120 mstat = nxt.getMotors()
121 for i, m
in enumerate(mstat):
122 print "(" , i,
"): ", m
124 nxt.setMotors([0,0,0])
128 sensors = [
"Touch",
"Sound",
"Light",
"USonic"]
129 sval = nxt.getSensors()
def resetPosition(self, relative=0)
def setMotors(self, vels)
def __init__(self, bsock=None)