Sending Commands

Issue motor commands to get your robot moving.

By the end of this tutorial you will be able to:

  1. Call your robot's pre-defined movement routines
  2. Construct simple motor messages with the BOW SDK to execute simple movements
  3. Link your keyboard events to your robot's locomotion routines for a basic teleoperation demo

Developing a robotics application is fundamentally about setting up a control loop that cycles continuously between three main tasks; sensing, decision-making, and acting.

The behaviour of humans and other animals can similarly be thought of in terms of this basic loop, with electrical signals to and from the brain conveying the information required to perceive and act upon the world, and the brain itself comprising networks of cells that operate on that information to coordinate behaviour. Some of the networks involved in decision-making are highly conserved across species, because they handle low-level decisions that benefit all animals, such as not deciding to walk forwards and backwards at the same time, whereas others are specific to certain species, like those which enable more complex problem-solving in primates. Decision-making is also about balancing risks and rewards that accumulate on different timescales, and about scheduling actions in anticipation of future events.

In short, decision-making is complicated, and while many important theories have been developed through the study of brains, animal behaviour, and robots, there is no simple recipe for enabling robots to make decisions as competently as we do. It will take good theories, great software, a few more tutorials, and the expertise of a much wider developer community to get there.

Fortunately, we don’t need to solve decision-making directly to start developing useful robotics applications. For now, we can close the loop by inserting our own brains into it. The BOW SDK handles the basic operations of information exchange between a robot’s brain (the computer running your applications) and its body, in much the same way as the brainstem handles signalling between biological brains and bodies. So the simplest way to close the loop is to convey robot sensor data to our own sensors, in the way we previously conveyed camera images to our eyes via a computer monitor, and to provide a similar means for enacting our decisions through the robot’s body, for example by moving a mouse, pressing keys, or waving a handheld controller.

Control loops that involve human decision-making in this way are referred to as teleoperation applications, and it won’t take long to have a simple demonstration up and running.

Take a look at the following to see what we're aiming for:

About the Application

The purpose of the application you will develop here is to enable users to call a robot's locomotion routines via key presses. The structure of the application is as follows:

Before we get stuck in:

If you are just browsing to get a sense of what's possible, take a look at the code online.

Running the Application

Navigate to the GettingStarted/SendingCommands/Python folder in the SDK Tutorials repository:

cd SDK-Tutorials/GettingStarted/SendingCommands/Python

Install any dependencies:

pip install -r requirements.txt

Execute the example program:

python main.py

Investigation

When the example program for this tutorial is running you will be able to see the robot's camera data, and you will be able to drive the robot around its environment by pressing the following keys:

KeyAction
WMove Forward
ATurn Left
SMove Backward
DTurn Right
EStrafe Right
QStrafe Left

Let's take a closer look at the key parts of the code:

The following function constructs and return a motor message based on the user key presses:

def keyboard_control():
    motorSample = bow_data.MotorSample()
    if 'w' in pressed_keys:
        print("Moving forward")
        motorSample.Locomotion.TranslationalVelocity.X = 0.2
        ...
    return motorSample

This function is called inside the main loop

 motorSample = keyboard_control()

The motorSample is then sent to the robot:

myrobot.motor.set(motorSample)

On this page