Hello, Drake!
From now on, get your hands dirty. Follow the steps to start building your own code.
Quick access to the tutorial demos
If you just want to see the result really quick, you could always skip the tutorial and use code on my github branch. Here's how.
Same process applies to all the other examples.
Create workspace
To run a simple example, we need a workspace that hosts C++ source files and BUILD.bazel
file.
Add files to the workspace
Create files named BUILD.bazel
and hello.cc
under examples/hello.
The code is available here.
Add the following contents to BUILD.bazel
.
Add the following contents to hello.cc
.
Compile and execute
Use the following command to build and run the code.
The BUILD.bazel
tells bazel
what and how to compile. So when we run the code, bazel
will find and build the code under that folder.
Now let's try add argument to the executable. Try the following and see what you get.
Hooray, you get your first Drake program running! Now you are ready to digest some real meat.
The Code Explained
BUILD.bazel
bazel
will search the whole directory recursively to find BUILD.bazel
. BUILD.bazel
specifies the sources and headers that should be built, and tells bazel
the target libraries and executables that should be generated. We need a BUILD.bazel
under the work space folder.
Load pre-defined bazel rule. We need to build Drake binary, so we load drake_cc_binary
at line 3.
Use drake_cc_binary
to define how the binary is going to be built. drake_cc_binary
specifies: 1. target executable name; 2. the files to be build; 3. all the required data (for example the robot mesh files); 4. dependencies.
Use //common:text_logging_gflags
and @gflags
as dependency. //common:text_logging_gflags
is a information logging tool. gflags
allows us to specify variables at run-time by passing arguments in command line, makes it easy to tune parameters without recompile.
hello.cc
Include gflags
header file. gflags
parses the command line parameters at run-time.
Include drake logging header file which contains function drake::log()
.
Define a variable FLAGS_your_name
with default value and explanation text. We could change the value before executing the binary by adding -- --your_name=Russ
.
Define the DoMain
function, which serves as our main process. This program plots a string to console.
Entrance to the program. The program starts by parsing the argument specified by user. And then it executes the DoMain()
function which plot the string with your name!
Last updated