Linus Atorf’s MotorControl Support

class nxt.motcont.MotCont(brick)

Interface to MotorControl.

This class provides an interface to Linus Atorf’s MotorControl NXC program. It is a wrapper which follows the MotorControl documentation and provides command strings and timing intervals as dictated there.

To use this module, you will need to put MotorControl22.rxe on your NXT brick. It can be built using NXC and the corresponding source can be found at https://github.com/schodet/MotorControl.

Use MotCont.start() to start the program. You can also start it manually my using the menu on the brick. When your script exits, it would be a good idea to do MotCont.stop().

Original MotorControl site is no longer available, but you can still find a mirror on web archive.

cmd(ports, power, tacholimit, speedreg=True, smoothstart=False, brake=False)

Send a CONTROLLED_MOTORCMD to MotorControl.

Parameters:
  • ports (nxt.motor.Port or Iterable[nxt.motor.Port]) – Port or ports to control, use one of the port identifiers, or an iterable returning one or two of them.

  • power (int) – Speed or power, -100 to 100.

  • tacholimit (int) – Position to drive to, 1 to 999999, or 0 for unlimited.

  • speedreg (bool) – True to enable regulation.

  • smoothstart (bool) – True to enable smooth start.

  • brake (bool) – True to hold brake at end of movement.

reset_tacho(ports)

Reset NXT tacho count.

Parameters:

ports (nxt.motor.Port or Iterable[nxt.motor.Port]) – Port or ports to control, use one of the port identifiers, or an iterable returning one to three of them.

is_ready(port)

Determine the state of a single motor.

Parameters:

port (nxt.motor.Port or Iterable[nxt.motor.Port]) – Port to control, use one of the port identifiers, or an iterable returning one of them.

Returns:

True if the motor is ready to accept new commands.

Return type:

bool

set_output_state(ports, power, tacholimit, speedreg=True)

Send a CLASSIC_MOTORCMD to MotorControl.

Parameters:
  • ports (nxt.motor.Port or Iterable[nxt.motor.Port]) – Port or ports to control, use one of the port identifiers, or an iterable returning one or two of them.

  • power (int) – Speed or power, -100 to 100.

  • tacholimit (int) – Position to drive to, 1 to 999999, or 0 for unlimited.

  • speedreg (bool) – True to enable regulation.

start(version=22)

Start the MotorControl program on the brick.

Parameters:

version (int) – Version to start, default to 22 (version 2.2).

It needs to already be present on the brick’s flash and named MotorControlXX.rxe, where XX is the version number passed as the version argument.

stop()

Stop the MotorControl program.

All this actually does is to stop the currently running program.