Robot Navigation - Blocks

Introduction to Robot Navigation

As alluded to in the Hello Robot - Robot Control section, robot control comes in many different forms. One of the control types to consider for robots with drivetrains, is robot navigation.

Robot navigation as a concept is dependent on the type of drivetrain and the type of operation mode. For instance, the code to control a mecanum drivetrain differs from the code used to control a differential drivetrain. There is also a difference between coding for teleoperated driving, with a gamepad, or coding for autonomous, where each movement of the robot must be defined within code.

The following section goes through some of the basics of programming for a differential drivetrain, as well as how to set up a teleoperated arcade style drivetrain code. The concepts and logic highlighted in this section are applicable to autonomous control, including the section Elapsed Time.

Sections

Goals of Section

What to consider when programming drivetrain motors and how to apply this to an arcade style teleoperated control.

Basics of Programming Drivetrains

For controlling the Class Bot V2 drivetrain, being able to control two motors simultaneously is important. This is done through the dual motor block within Blocks. To access the dual motor block, at the top of the Categorize Blocks section there is a drop down menu for Actuators. Selecting DcMotor will drop down the options Dual and another drop down menu Extended. Select Dual to access the dual motor blocks.

Programming Drivetrain Motors

When there are multiple of the same type of variable (such as multiple Dc Motor variables) the variable specific blocks will choose a default variable based on alphabetical order. For this example Op Mode Dc Motor blocks will default to the arm variable.

Use the variable drop down menu on the block to change from arm to rightmotor.

Before moving on try running the code as is and consider the following questions:

  • What behavior is the robot exhibiting?

  • What direction is the robot spinning in?

When motors run at different speeds they spin along their center pivot point. But the motors are both set to a power (or duty cycle) of 1?

DC Motors are capable of spinning in two different directions depending on the current flow: clockwise and counter clockwise. When using a positive power value the Control Hub sends current to the motor for it to spin in a clockwise direction.

With the Class Bot and current code, both motors are currently set to run in the clockwise direction. If you set the robot on blocks and run the code again though, you can see that the motors run in opposing directions. With the mirrored way the motors mount to the drivetrain, one motor is naturally the inverse of the other.

Why would the inverse motor cause the robot to spin in a circle? Both speed and direction of rotation of the wheels impact the overall direction the robot moves in. In this case, both motors were assigned to have the same power and direction but how the motors transfer motion to the wheels, causes the robot to spin instead of moving forward.

Check the Introduction to Motion section for more information on the mechanics of transferring motion and power.

In the info block above you were asked to determine which direction the robot spun in. The robot pivots in the direction of the inversed motor. For instance, when the right motor is the inversed motor the robot will pivot to the right. If the left motor is the inversed motor the robot will pivot to the left.

The Affect of Drivetrain Motors on Drivetrain Movement

Teleoperated Driving - Arcade Style

Recall that when the motors were running in opposing directions the robot spun in circles. This same logic will be used to control the robot using the arcade style of control mentioned in the Hello Robot - Autonomous Robot section.

Programming with gamepads

Remember positive/negative values inputted by the gamepad's y-axis are inverse of the positive/negative values of the motor.

To better understand consider the following table. The table shows the expected value generated from moving the joystick all the way in one direction, along the axis. For instance, when the joystick is pushed all the way in the upwards direction the coordinate values are (0,1).

The table below assumes that the the yyvalues from the gamepad have been inverted in code when assigned to the variable yy .

Joystick Direction

xx

yy

0

1

0

-1

-1

0

1

0

Much like the gamepads, the numerical value for setPower is in a range of -1 to 1. The absolute value of the assigned number determines percentage of duty cycle. As an example, 0.3 and -0.3 both indicate that the motor is operating at a duty cycle of 30%. The sign of the number indicates the direction the motor is rotating in. To better understand, consider the following graphic.

When a motor is assigned a setPowervalue between -1 and 0, the motor will rotate in the direction it considers to be reverse. When a motor is assigned a value between 0 and 1, it will rotate forward.

In the Programming Drivetrain Motors section, it was discussed that a robot rotates when the motors are moving in opposing directions. However, this has more to do with both speed and direction. To think of it numerically, a differential drivetrain will turn to the right when the setPower value for the right motor is less than that of the left motor. This is exhibited in the following example.

rightMotor = leftMotor

Forward or Reverse

rightMotor > leftMotor

Left Turn

rightMotor < leftMotor

Right Turn

In an arcade drive, the following joy stick inputs (directions) need to correspond with the following outputs (motor power values).

Joystick Direction

( xx , yy )

rightmotor

leftmotor

(0,1)

1

1

(0,-1)

-1

-1

(-1,0)

1

-1

(1,0)

-1

1

To get the outputs expressed in the table above, the gamepad values must be assigned to each motor in a meaningful way, where. Algebraic principles can be used to determine the two formulas needed to get the values. However, the formulas are provided below.

rightmotor=yxleftmotor=y+xrightmotor = y-x \\ leftmotor = y+x

With this you now have a functional teleoperated arcade drive!

Last updated