Jekyll2017-04-19T17:26:46+00:00https://mit-racecar.github.io//RACECARA Powerful Platform for Robotics Research and TeachingCreating Flame Graphs in ROS2017-03-21T00:00:00+00:002017-03-21T00:00:00+00:00https://mit-racecar.github.io//2017/03/21/flame<h2 id="creating-flame-graphs-in-ros">Creating Flame Graphs in ROS</h2>
<object style="margin-top: 20px;" data="/img/flame_filtered.svg" type="image/svg+xml" class="full_width"></object>
<p>This flame graph was generated with the below steps (with filtering) for the staff solution of Lab 5. It’s interactive, click on it! <a href="/img/flame_filtered.svg">Click here to open in a new tab.</a></p>
<h3 id="overview">Overview</h3>
<ol>
<li>Modify code to allow for direct invocation</li>
<li>Run your code while collecting profiling information</li>
<li>(optional) Filter the profiling information to contain only the interesting bits</li>
<li>Generate flame graphs with flamegraph.pl</li>
<li>View and interact with the results in a web browser</li>
</ol>
<h3 id="specifics">Specifics</h3>
<h4 id="1-modify-code-to-allow-for-direct-invocation">1. Modify code to allow for direct invocation</h4>
<p>The primary consideration is how to load params which would be typically be provided natively in ROS when you use roslaunch. This is how we do it, you might be able to discover a better method. This should work both with direct invocation and with the standard roslaunch method.</p>
<p>Modify your code to accept a “–config” argument which allows you to specify a yaml file.</p>
<p>Python code: particle_filter.py</p>
<div class="highlighter-rouge"><pre class="highlight"><code>import argparse
parser = argparse.ArgumentParser(description='Particle filter.')
parser.add_argument('--config', help='Path to yaml file containing config parameters. \
Helpful for calling node directly with Python for profiling.')
def load_params_from_yaml(fp):
from yaml import load
with open(fp, 'r') as infile:
yaml_data = load(infile)
for param in yaml_data:
print "param:", param, ":", yaml_data[param]
rospy.set_param("~"+param, yaml_data[param])
if __name__=="__main__":
rospy.init_node("particle_filter")
args,_ = parser.parse_known_args()
if args.config:
load_params_from_yaml(args.config)
pf = ParticleFiler()
rospy.spin()
</code></pre>
</div>
<p>YAML config parameters: params.yaml</p>
<div class="highlighter-rouge"><pre class="highlight"><code>scan_topic: "/scan"
odometry_topic: "/vesc/odom"
angle_step: 18
max_particles: 5000
range_method: "pcddt"
theta_discretization: 108
max_range: 10
# etc...
</code></pre>
</div>
<h4 id="2-run-your-code-while-collecting-profiling-information">2. Run your code while collecting profiling information</h4>
<p>First install this: <a href="https://github.com/evanhempel/python-flamegraph">https://github.com/evanhempel/python-flamegraph</a></p>
<div class="highlighter-rouge"><pre class="highlight"><code>pip install git+https://github.com/evanhempel/python-flamegraph.git
</code></pre>
</div>
<p>Example command line invocation:</p>
<div class="highlighter-rouge"><pre class="highlight"><code># 0.001 is the sampling rate (1000Hz here)
# out.log is the output file
python -m flamegraph -i 0.001 -o out.log ./src/particle_filter.py --config ./params.yaml
</code></pre>
</div>
<h4 id="3-optional-filter-the-profiling-information-to-contain-only-the-interesting-bits">3. (optional) Filter the profiling information to contain only the interesting bits</h4>
<p>If you do this with ROS, there will be a bunch of extra stack information in there which is not relevant to you. You can filter the log file to contain only the information you care about with grep. It might help to look at the unfiltered version to identify the functions you care about.</p>
<p>Example command line invocation:</p>
<div class="highlighter-rouge"><pre class="highlight"><code># filter only stack frames above function called "/scan`update"
grep scan\`update out.log > out_filtered.log
</code></pre>
</div>
<h4 id="4-generate-flame-graphs-with-flamegraphpl">4. Generate flame graphs with flamegraph.pl</h4>
<p>First download the necessary Perl script from here: <a href="https://github.com/brendangregg/FlameGraph/blob/master/flamegraph.pl">https://github.com/brendangregg/FlameGraph/blob/master/flamegraph.pl</a></p>
<p>Example command line invocation:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>./flamegraph.pl --title "Your title here" out.log > flames.svg
./flamegraph.pl --title "Your title here" out_filtered.log > flames_filtered.svg
</code></pre>
</div>
<h4 id="5-view-and-interact-with-the-results-in-a-web-browser">5. View and interact with the results in a web browser</h4>
<p>Open flames.svg in your web browser.</p>
<object style="margin-top: 20px;" data="/img/flame.svg" type="image/svg+xml" class="full_width"></object>
<p>Unfiltered flame graph for the staff solution of Lab 5. Clearly there’s some extra information as compared to the filtered version. <a href="/img/flame.svg">Click here to open in a new tab.</a></p>
<h3 id="notes">Notes</h3>
<p>We recommend making a small set of bash scripts to implement the above steps, which should make it easier to remember the commands.</p>Corey WalshCreating Flame Graphs in ROSGetting Started2017-01-01T00:00:00+00:002017-01-01T00:00:00+00:00https://mit-racecar.github.io//2017/01/01/getting-started<h2 id="connecting-to-the-car">Connecting to the Car</h2>
<ol>
<li>Connect to the wifi router that belongs to your car. The 5GHz band works best if it is available.
<ul>
<li>The wifi password is <code class="highlighter-rouge">g0_fast!</code></li>
</ul>
</li>
<li><code class="highlighter-rouge">ssh racecar@192.168.0.[carnumber]</code>
<ul>
<li>password: <code class="highlighter-rouge">racecar@mit</code></li>
</ul>
</li>
</ol>
<h2 id="launching-the-racecar">Launching the racecar</h2>
<p>All racecar software can be launched from a single launch file. This file will launch the laser scanner, telop, and wheel controls. You can launch the file with the following:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>roslaunch racecar teleop.launch
</code></pre>
</div>Ariel AndersConnecting to the Car Connect to the wifi router that belongs to your car. The 5GHz band works best if it is available. The wifi password is g0_fast! ssh racecar@192.168.0.[carnumber] password: racecar@mitFAQ2017-01-01T00:00:00+00:002017-01-01T00:00:00+00:00https://mit-racecar.github.io//2017/01/01/faq<h2>Table of Contents</h2>
<ul id="markdown-toc">
<li><a href="#common-errors-and-fixes" id="markdown-toc-common-errors-and-fixes">Common errors and fixes</a> <ul>
<li><a href="#failed-to-connect-to-the-vesc" id="markdown-toc-failed-to-connect-to-the-vesc"><code class="highlighter-rouge">Failed to connect to the VESC</code></a></li>
</ul>
</li>
<li><a href="#zed-camera-is-plugged-in-but-cant-find-configuration" id="markdown-toc-zed-camera-is-plugged-in-but-cant-find-configuration">Zed camera is plugged in but can’t find configuration</a></li>
</ul>
<h2 id="common-errors-and-fixes">Common errors and fixes</h2>
<h3 id="failed-to-connect-to-the-vesc"><code class="highlighter-rouge">Failed to connect to the VESC</code></h3>
<p><strong>Error message:</strong></p>
<p><code class="highlighter-rouge">Failed to connect to the VESC, SerialException Failed to open the serial port to the VESC. IO Exception (16): Device or resource busy, file /tmp/binarydeb/ros-kinetic-serial-1.2.1/src/impl/unix.cc, line 151. failed..</code></p>
<p><strong>Solution:</strong></p>
<ul>
<li>Make sure Traxxas VESC battery is plugged in.</li>
<li>Make sure that USB hub on bottom of robot has a blue (power) light lit.</li>
<li>Make sure that the USB cable from the VESC is plugged into the VESC and the USB hub.</li>
<li>Try again, sometimes you retry a few times before it connects</li>
</ul>
<h2 id="zed-camera-is-plugged-in-but-cant-find-configuration">Zed camera is plugged in but can’t find configuration</h2>
<p>Generally this problem occurs when the camera is used for the first time and does not yet have the calibration parameters. If you have SSHed into the car with X-Forwarding, it can often download the parameters itself once it detects that they are missing. If you have not used X-Forwarding, you will get the following error…</p>
<p><strong>Error message</strong></p>
<div class="highlighter-rouge"><pre class="highlight"><code>No calibration file found for this ZED Camera. Trying to download it...
QXcbConnection: Could not connect to display
Aborted
Didn't manage to load calibration file .. Setting file for your ZED may not exist on this PC.
* Option 1 : Launch ZED Explorer App with --dc 12441
* Option 2 : Manually download your calibration file by following the instructions on http://calib.stereolabs.com
ZED SDK >> (Init) Failed to load Calibration Parameters...
</code></pre>
</div>
<p><strong>Solution:</strong></p>
<ol>
<li>Make sure the car is connected to the internet
<ul>
<li>Ethernet cable should connect the wall port to the port on the router labeled “internet”</li>
<li>Verify that you have access to the internet: ping google.com</li>
</ul>
</li>
<li>Connect to the router with your computer and SSH into the car with X-Forwarding enabled
<div class="highlighter-rouge"><pre class="highlight"><code>ssh -x racecar@192.168.0.[Car #]
</code></pre>
</div>
</li>
<li>Download calibration parameters fro mthe internet using the Zed Explorer tool
<div class="highlighter-rouge"><pre class="highlight"><code>/usr/local/zed/tools/ZED\ Explorer --download_calibration
</code></pre>
</div>
</li>
<li>Test that it worked. This should take a few seconds to run…
<div class="highlighter-rouge"><pre class="highlight"><code>roslaunch zed_wrapper zed.launch
</code></pre>
</div>
</li>
</ol>Ariel Anders, Corey WalshTable of Contents