예제 #1
0
 def syncmotorsforever(self, power):
     if self._bricks:
         if not((power < -127) or (power > 127)):
             try:
                 motorB = Motor(self._bricks[self.active_nxt], PORT_B)
                 motorC = Motor(self._bricks[self.active_nxt], PORT_C)
                 syncmotors = SynchronizedMotors(motorB, motorC, 0)
                 syncmotors.run(power)
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_POWER)
     else:
         raise logoerror(ERROR_BRICK)
예제 #2
0
 def syncmotors(self, power, turns):
     if self._bricks:
         if not((power < -127) or (power > 127)):
             if turns < 0:
                 turns = abs(turns)
                 power = -1 * power
             try:
                 motorB = Motor(self._bricks[self.active_nxt], PORT_B)
                 motorC = Motor(self._bricks[self.active_nxt], PORT_C)
                 syncmotors = SynchronizedMotors(motorB, motorC, 0)
                 syncmotors.turn(power, int(turns*360))
             except:
                 raise logoerror(ERROR_GENERIC)
         else:
             raise logoerror(ERROR_POWER)
     else:
         raise logoerror(ERROR_BRICK)
예제 #3
0
Added sonar readings with velocity and acceloration calculations for both. 

@author: benjamin
"""

from time import sleep
from nxt.motor import Motor, PORT_A, PORT_C, SynchronizedMotors
from nxt.sensor import Ultrasonic, PORT_1
import nxt.locator
import string

brick = nxt.locator.find_one_brick()
left = Motor(brick, PORT_C)
right = Motor(brick, PORT_A)
tracks = SynchronizedMotors(left, right, 0)
tacho_zero = [0,0] # An array for resetting the tacho readings. 

# This program uses the physics notiation of:
# X for position
# V for velocity, a.k.a: X-dot
# A for acceleration, a.k.a: X-double-dot

tachoX0 = [0,0] # Current tacho position in degrees
tachoX1 = [0,0] # Previous tacho position
tachoV0 = [0,0] # Current tacho velocity in dgrees per second
tachoV1 = [0,0] # Tacho velocity at previous time step
tachoA0 = [0,0] # Current tacho acceleration in dgrees per second per second

sonarX0 = [0,0] # Current sonar reading provides distance in cm from objects
sonarX1 = [0,0] # Previous sonar reading