Robot App Store Developer Program

robots-app-store-developer-program

Knowledge Base

How to make LEGO NXT drive

  By Anna Sandler

Make sure you are familiar with the "How to Control Lego NXT Motors" tutorial before you continue reading this chapter.

How to drive always straight

In order to drive straight, all the motors should rotate at the same speed.
The actual speed of each motor can be different, although both motors are set at the same Motor power set point value.

The following are the reasons for the speed gap:
  • Due to tiny differences of motor’s structure, two motors that are set to the same Motor power set point, will rotate at different speed.
  • Another reason for different rotation speed between the motors is the external physical overload due to differences in the surface.
The best way to ensure a straight driving of a two- wheel vehicle is by using a synchronization regulation mode.
This way, the NXT firmware will adjust the speed by adding more power to the motors according to the external physical load on the motors.

Note- The regulation mode must be set on both motors.

Example:

The following telegrams will make NXT to drive straight using the motor synchronization mode.

Preparations- build a basic vehicle according to the quick start. Connect the left motor to the B port and the right motor to the C port.

The command that is sent to NXT is:
0x0C 0x00 0x80 0x04 0x01 0x32 0x05 0x02 0x00 0x20 0x00 0x00 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x32 0x05 0x02 0x00 0x20 0x00 0x00 0x00 0x00

Explanation:

  • Byte 0-1: Command length of 12 bytes (0x0C) LSB first.
  • Byte 2: Command type 0x80- direct command without the reply message.
  • Byte 3: Command 0x04- set motor output state.
  • Byte 4: Motor output port. 0x01 in the first telegram for motor port B and 0x02 in the second telegram for motor port C.
  • Byte 5: Motor power set point. 0x32 for 50% of motor’s power speed.
  • Byte 6: Motor mode byte. 0x05 for motor ON with regulation.
  • Byte 7: Regulation mode. 0x02 for regulating the synchronization of two motors.
  • Byte 8: Turn ratio. 0x00- for a straight regulated driving.
  • Byte 9: Run state. 0x20- for running constantly.
  • Byte 10-13: Tacho limit LSB first. 0x00 for no change.

How to drive with constant speed

Driving the NXT vehicle on a rough surface, causes the robot to slow down although motor's power is working as defined.
In this case, the problematic motor should get more power in order to get his initial speed.
In order to drive with a constant speed, the power set point should be always adjusted relatively to the power set point value that was set by the SetOutputState command.
The best way to ensure the constant speed is by using a speed regulation mode.
This way, the NXT firmware will adjust the speed by adding more power to the motor according to the external physical load on the motor.

Example:

The following telegram will make NXT to drive with constant speed using the speed regulation mode on motor that is connected to B port.

The command that is sent to NXT is:
0x0C 0x00 0x80 0x04 0x01 0x32 0x05 0x01 0x00 0x20 0x00 0x00 0x00 0x00

Explanation:

  • Byte 0-1: Command length of 12 bytes (0x0C) LSB first.
  • Byte 2: Command type 0x80- direct command without the reply message.
  • Byte 3: Command 0x04- set motor output state.
  • Byte 4: Motor output port. 0x01 for motor port B.
  • Byte 5: Motor power set point. 0x32 for 50% of motor’s power speed.
  • Byte 6: Motor mode byte. 0x05 for motor ON with regulation.
  • Byte 7: Regulation mode. 0x01 for regulating the speed of the motor.
  • Byte 8: Turn ratio. 0x00- for a straight regulated driving.
  • Byte 9: Run state. 0x20- for running constantly.
  • Byte 10-13: Tacho limit LSB first. 0x00 for no change.

How to make an immediate turn

The best way to make an immediate turn of a two-wheel vehicle is by setting the rotation direction of one motor forward while setting the rotation direction of the second motor backwards.

For faster results, both motors should rotate in the same speed.

The direction of the rotation is set by the sign of the Motor power set point byte:
  • Negative Motor power set point for rotating backward;
  • Positive Motor power set point for rotating forward;
Setting the direction of the turn:
  • For turning left: The rotation direction of the left motor (the motor that is closer to the turning direction) should be backwards while the rotation direction of the right motor is forward;
  • For turning right: The rotation direction of the right motor (the motor that is closer to the turning direction) should be backwards while the rotation direction of the left motor is forward;

Example:

The following telegrams will make NXT to turn right.

Preparations- build a basic vehicle according to the quick start. Connect the left motor to the B port and the right motor to the C port.

The command that is sent to NXT is:
0x0C 0x00 0x80 0x04 0x01 0xCF 0x01 0x00 0x00 0x20 0x00 0x00 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x32 0x01 0x00 0x00 0x20 0x00 0x00 0x00 0x00

Explanation:

  • Byte 0-1: Command length of 12 bytes (0x0C) LSB first.
  • Byte 2: Command type 0x80- direct command without the reply message.
  • Byte 3: Command 0x04- set motor output state.
  • Byte 4: Motor output port. 0x01 in the first telegram for motor port B and 0x02 in the second telegram for motor port C.
  • Byte 5: Motor power set point. 0x32 for 50% of motor’s power speed forward direction, 0xCF 50% for backward direction.
  • Byte 6: Motor mode byte. 0x01 for motor ON.
  • Byte 7: Regulation mode. 0x00 for disabling regulating.
  • Byte 8: Turn ratio. 0x00- for a straight regulated driving or non-regulated driving.
  • Byte 9: Run state. 0x20- for running constantly.
  • Byte 10-13: Tacho limit LSB first. 0x00 for no change.

Example:

The following telegrams will make NXT to turn left.

Preparations- build a basic vehicle according to the quick start. Connect the left motor to the B port and the right motor to the C port.

The command that is sent to NXT is:
0x0C 0x00 0x80 0x04 0x01 0x32 0x01 0x00 0x00 0x20 0x00 0x00 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0xCF 0x01 0x00 0x00 0x20 0x00 0x00 0x00 0x00

Explanation:

See explanation above.

How to smoothly change the driving speed

There are two ways for changing the driving speed smoothly:
  • Negative Motor power set point for rotating backward;
  • Positive Motor power set point for rotating forward;
Setting the direction of the turn:
  • Manually- Sending the SetOutputState command several times, each time with increased/decreased Motor power set point. This option is not recommended.
  • Automatically- Configure the NXT firmware to automatically increase/decrease the speed from the current speed up to the specified speed.
For automatic smooth adjustments to the current speed, use a motor synchronization regulation mode with Run state as a Ramp-up or Ramp-down and a Techo-limit value that is greater than 19FF in hex.

Note- The regulation mode must be set on both motors.

Example for smoothly increasing the speed:

The following telegrams will make NXT to drive straight using the motor synchronization mode when the speed is smoothly increased.

Preparations- build a basic vehicle according to the quick start. Connect the left motor to the B port and the right motor to the C port.

The command that is sent to NXT for a straight driving at half motor power speed is:
0x0C 0x00 0x80 0x04 0x01 0x32 0x05 0x02 0x00 0x20 0x00 0x00 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x32 0x05 0x02 0x00 0x20 0x00 0x00 0x00 0x00

The command that is sent to NXT for a straight driving while smoothly increasing the speed to full motor power speed is:
0x0C 0x00 0x80 0x04 0x01 0x64 0x05 0x02 0x00 0x10 0xFF 0x19 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x64 0x05 0x02 0x00 0x10 0xFF 0x19 0x00 0x00

Explanation:

  • Byte 0-1: Command length of 12 bytes (0x0C) LSB first.
  • Byte 2: Command type 0x80- direct command without the reply message.
  • Byte 3: Command 0x04- set motor output state.
  • Byte 4: Motor output port. 0x01 in the first telegram for motor port B and 0x02 in the second telegram for motor port C.
  • Byte 5: Motor power set point. 0x32 for 50% of motor’s power speed, 0x64 for 100%.
  • Byte 6: Motor mode byte. 0x05 for motor ON with regulation.
  • Byte 7: Regulation mode. 0x02 for regulating the synchronization of two motors.
  • Byte 8: Turn ratio. 0x00- for a straight regulated driving.
  • Byte 9: Run state. 0x20- for running constantly, 0x10 for smoothly increase motor’s speed, 0x40 for smoothly decreasing motor’s speed.
  • Byte 10-13: Tacho limit LSB first. 0x00 for no change, 0xFF 0x19 0x00 0x00 for the lowest rotation distance to get the smoothest speed changes.

Example for smoothly decreasing the speed:

The following telegrams will make NXT to drive straight using the motor synchronization mode when the speed is smoothly decreased.

Preparations- build a basic vehicle according to the quick start. Connect the left motor to the B port and the right motor to the C port.

The command that is sent to NXT for a straight driving at full motor power speed is:
0x0C 0x00 0x80 0x04 0x01 0x64 0x05 0x02 0x00 0x20 0x00 0x00 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x64 0x05 0x02 0x00 0x20 0x00 0x00 0x00 0x00

The command that is sent to NXT for a straight driving while smoothly decrease the speed to half motor power speed is:
0x0C 0x00 0x80 0x04 0x01 0x32 0x05 0x02 0x00 0x40 0xFF 0x19 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x32 0x05 0x02 0x00 0x40 0xFF 0x19 0x00 0x00

Explanation:

See explanation above.

How to make motors go back and forth on opposite ways

This mode cannot be used for driving purposes, but it can be used on other NXT models.
When using a motor synchronization regulation mode with turn ration while one of the motors is set to a negative motor power set point, the motors will rotate at opposite direction while going back and forth due to the synchronization regulation.

Note- The regulation mode must be set on both motors.

Example:

The following telegrams will make both motors to rotate back and forth at opposite directions.

The command that is sent to NXT is:
0x0C 0x00 0x80 0x04 0x01 0x64 0x05 0x02 0x64 0x20 0x00 0x00 0x00 0x00
0x0C 0x00 0x80 0x04 0x02 0x9C 0x05 0x02 0x64 0x20 0x00 0x00 0x00 0x00

Explanation:

  • Byte 0-1: Command length of 12 bytes (0x0C) LSB first.
  • Byte 2: Command type 0x80- direct command without the reply message.
  • Byte 3: Command 0x04- set motor output state.
  • Byte 4: Motor output port. 0x01 in the first telegram for motor port B and 0x02 in the second telegram for motor port C.
  • Byte 5: Motor power set point. 0x64 for 100% of motor’s power speed for a forward rotation, 0x9C for 100% backward rotation.
  • Byte 6: Motor mode byte. 0x05 for motor ON with regulation.
  • Byte 7: Regulation mode. 0x02 for regulating the synchronization of two motors.
  • Byte 8: Turn ratio. 0x64- for opposite rotation 100% of the Motor set point value.
  • Byte 9: Run state. 0x20- for running constantly.
  • Byte 10-13: Tacho limit LSB first. 0x00 for no change.

read here cheats why men cheat on beautiful women
married and want to cheat my wife cheated now what my wife cheated on me with my father
my wife cheated now what husbands that cheat looking for affair
will my wife cheat again link how do i know if my wife has cheated
click why men have affairs married men having affairs
reasons people cheat husband cheated on me wife cheat story
sumatriptan succ sumatriptan succ sumatriptan succ







Related Robot-Apps™

Comments