Example #1
0
def run():
    conn = Connection(3)
    msg = messages.GetBatteryLevel()
    conn.send(msg)
    resp = conn.receive()
    print('received response: %s' % type(resp))
    print('battery voltage is %d mV.' % resp.millivolts)
Example #2
0
def run():
    conn = Connection(5)

    conn.send(SetOutputState(OutputPort.b))
    conn.send(SetOutputState(OutputPort.c))

    regulation_params = dict(
        use_regulation=True,
        regulation_mode=RegulationMode.motor_sync,
        turn_ratio=100,
    )
    run_params = dict(
        run_state=RunState.running,
        set_power=75,
        motor_on=True,
    )
    all_params = dict(regulation_params)
    all_params.update(run_params)
    reg_cmd = SetOutputState(OutputPort.b, **all_params)
    conn.send(reg_cmd)
    time.sleep(2)
    run_cmd = SetOutputState(OutputPort.c, **all_params)
    run_cmd.turn_ratio = 5
    conn.send(run_cmd)

    time.sleep(5)

    stop_cmd = SetOutputState(OutputPort.b)
    conn.send(stop_cmd)
    stop_cmd = SetOutputState(OutputPort.c)
    conn.send(stop_cmd)
Example #3
0
def runSorter():
    conn = Connection('/dev/rfcomm0')
    port = enum.InputPort(1)
    print(conn)
    conn.send(
        messages.SetInputMode(
            port,
            messages.SensorType.switch,
            messages.SensorMode.boolean,
        ))
    #print(', '.join(field[:4] for field in messages.InputValues.fields))
    #querySorter(conn,port)
    #cycle_motor_a(conn)
    conn.close()
Example #4
0
	def __init__(self, options):
		self.conn = Connection(options.port)
		if options.scale_a:
			self.scale_a = options.scale_a
		if options.scale_b:
			self.scale_b = options.scale_b
		if options.scale_c:
			self.scale_c = options.scale_c
		try:
			self.input = Joystick.enumerate_devices()[0]
		except IndexError:
			raise RuntimeError("Could not find any joystick controllers.")
		# keep track of the state of the controller (initial state
		#  assumes all values are zero).
		self.controller_state = defaultdict(lambda: 0)

		# register the joystick on_axis event
		self.input.event(self.on_axis)
Example #5
0
import time
import sys
from jaraco.nxt import Connection, messages
from jaraco.nxt.routine import get_port
from jaraco.nxt.messages import RegulationMode, RunState
from jaraco.nxt import _enum as enum

conn = Connection("/dev/tty.NXT-DevB")
right_port = enum.InputPort(1)
left_port = enum.InputPort(2)
light_port = left_port
motor_port_a = get_port('a', messages.OutputPort)
motor_port_b = get_port('b', messages.OutputPort)
conn.send(
    messages.SetInputMode(light_port, messages.SensorType.light_active,
                          messages.SensorMode.raw))

Blue_Reading = 540
Gray_Reading = 580


def moveMotor(conn, port, power, time):
    cmd = messages.SetOutputState(port,
                                  motor_on=True,
                                  set_power=power,
                                  run_state=messages.RunState.running)
    conn.send(cmd)
    time.sleep(time)
    cmd = messages.SetOutputState(port, motor_on=False)
    conn.send(cmd)
Example #6
0
                motor_on=True,
                regulation_mode=RegulationMode.motor_sync,
                run_state=RunState.running,
                set_power=power_mul * 75,  # slower is more accurate
                tacho_limit=quarter_turn_ticks,
                turn_ratio=100,  # turn right
            ),
        ]

        list(map(connection.send, cmds))

        # leave the bot time to start turning
        time.sleep(1)

        # Check for the end of rotation
        wait_for_motor(connection, OutputPort.b)

        # give it a little time to correct its mistakes (hey synchronisation
        # mode :-)
        time.sleep(2)

        # apparently we've stopped!
        # then release the motors
        initialize()


if __name__ == '__main__':
    connection = Connection(port)
    initialize()
    run()
Example #7
0
def run():
    conn = Connection('COM4')
    cycle_motor_a(conn)

    conn.close()
Example #8
0
def run():
    conn = Connection('COM4')
    cycle_motor(conn, 'b')

    conn.close()