Ejemplo n.º 1
0
# Simple but fun idea. Press both touch sensors together to unleash balls

from ch.aplu.nxt import NxtRobot, Motor, MotorPort, TouchSensor, SensorPort, Tools

robot = NxtRobot()
gunmotor = Motor(MotorPort.A)
ts1 = TouchSensor(SensorPort.S1)
ts2 = TouchSensor(SensorPort.S2)
robot.addPart(gunmotor)
robot.addPart(ts1)
robot.addPart(ts2)

while true:
    if ts1.isPressed() and ts2.isPressed():
        gunmotor.forward()
    else:
        gunmotor.stop()
Ejemplo n.º 2
0
# "Lazy robot" that stays still until you bump a touch sensor
# bumping the right touch sensor gets the right wheel to spin for a time
# bumping the left gets the left wheel to do likewise. Logic is
# relatively complex because we need to keep time for both wheels
# simultaneously, not sure if we want to use this.

from ch.aplu.nxt import NxtRobot, Motor, MotorPort, TouchSensor, SensorPort, Tools

robot = NxtRobot()
motor1 = Motor(MotorPort.B)
motor2 = Motor(MotorPort.C)
ts1 = TouchSensor(SensorPort.S1)
ts2 = TouchSensor(SensorPort.S2)
robot.addPart(motor1)
robot.addPart(motor2)
robot.addPart(ts1)
robot.addPart(ts2)

m1counter = 0
m2counter = 1
while true:
    if (ts1.isPressed()):
        if (m1counter == 0):
            motor1.forward()
        m1counter = 5
    if (ts2.isPressed()):
        if (m2counter == 0):
            motor2.forward()
        m2counter = 5
    if (m1counter == 0):
        motor1.stop()
Ejemplo n.º 3
0
# A cautious robot that stays still until approached from front
# backs away each time it is approached from front 5 times
# if it senses it is backed against the wall it starts shooting briefly
# after backing away a full 5 times goes berserk and shoots all ammo left

from ch.aplu.nxt import NxtRobot, Motor, MotorPort, UltrasonicSensor, TouchSensor, SensorPort, Tools, LightSensor

robot = NxtRobot()
gunmotor = Motor(MotorPort.A)
motor1 = Motor(MotorPort.B)
motor2 = Motor(MotorPort.C)
ts1 = TouchSensor(SensorPort.S2)
ts2 = TouchSensor(SensorPort.S3)
us = UltrasonicSensor(SensorPort.S4)
robot.addPart(gunmotor)
robot.addPart(motor1)
robot.addPart(motor2)
robot.addPart(ts1)
robot.addPart(ts2)
robot.addPart(us)

def back_away(m1, m2, t):
    m1.stop()
    m2.stop()
    m1.backward
    m2.backward()
    Tools.delay(t)
    m1.stop()
    m2.stop()

def shoot(m, t):
Ejemplo n.º 4
0
# A simple maze-traversing two-wheeled robot
# that does the additional aggressive thing of
# open firing on anything that appears before it
# suddenly!

from ch.aplu.nxt import NxtRobot, Motor, MotorPort, UltrasonicSensor, TouchSensor, SensorPort, Tools, LightSensor

robot = NxtRobot()
gunmotor = Motor(MotorPort.A)
motor1 = Motor(MotorPort.B)
motor2 = Motor(MotorPort.C)
ts1 = TouchSensor(SensorPort.S2)
ts2 = TouchSensor(SensorPort.S3)
us = UltrasonicSensor(SensorPort.S4)
robot.addPart(gunmotor)
robot.addPart(motor1)
robot.addPart(motor2)
robot.addPart(ts1)
robot.addPart(ts2)
robot.addPart(us)


def move_backward(m1, m2, t):
    m1.stop()
    m2.stop()
    m1.backward
    m2.backward()
    Tools.delay(t)
    m1.stop()
    m2.stop()