Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
annikadl committed Mar 17, 2024
1 parent 6cde604 commit 73a04fe
Show file tree
Hide file tree
Showing 49 changed files with 7,113 additions and 0 deletions.
103 changes: 103 additions & 0 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &mdash; assignment_2_2023 1.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
<link rel="stylesheet" type="text/css" href="../_static/graphviz.css?v=eafc0fe6" />


<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js?v=359c27e9"></script>
<script src="../_static/doctools.js?v=888ff710"></script>
<script src="../_static/sphinx_highlight.js?v=4825356b"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head>

<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >



<a href="../index.html" class="icon icon-home">
assignment_2_2023
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<!-- Local TOC -->
<div class="local-toc"></div>
</div>
</div>
</nav>

<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">assignment_2_2023</a>
</nav>

<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Overview: module code</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">

<h1>All modules for which code is available</h1>
<ul><li><a href="scripts/info_service.html">scripts.info_service</a></li>
<li><a href="scripts/last_target_service.html">scripts.last_target_service</a></li>
<li><a href="scripts/set_target_client.html">scripts.set_target_client</a></li>
</ul>

</div>
</div>
<footer>

<hr/>

<div role="contentinfo">
<p>&#169; Copyright 2024, Annika Delucchi.</p>
</div>

Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.


</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>

</body>
</html>
204 changes: 204 additions & 0 deletions docs/_modules/scripts/info_service.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>scripts.info_service &mdash; assignment_2_2023 1.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />
<link rel="stylesheet" type="text/css" href="../../_static/graphviz.css?v=eafc0fe6" />


<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script src="../../_static/jquery.js?v=5d32c60e"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js?v=359c27e9"></script>
<script src="../../_static/doctools.js?v=888ff710"></script>
<script src="../../_static/sphinx_highlight.js?v=4825356b"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>

<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >



<a href="../../index.html" class="icon icon-home">
assignment_2_2023
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<!-- Local TOC -->
<div class="local-toc"></div>
</div>
</div>
</nav>

<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">assignment_2_2023</a>
</nav>

<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
<li class="breadcrumb-item active">scripts.info_service</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">

<h1>Source code for scripts.info_service</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">.. module:: info_service</span>
<span class="sd"> :platform: Unix</span>
<span class="sd"> :synopsis: Python module for the assignment_2_2023</span>
<span class="sd">.. moduleauthor:: Annika Delucchi</span>
<span class="sd"> </span>
<span class="sd">Description:</span>
<span class="sd"> This module implements a ROS node that provides a service to retrieve the distance from the goal and the average velocity of the robot.</span>
<span class="sd"> To make it feasible, a service file `info_service.srv` is created in the package directory, defining the expected service response type.</span>
<span class="sd"> The subscriber implemented in this node&#39;s callback function extracts the target position from ROS parameters and the actual position from the custom message sent by `set_target_client.py`. The distance is computed as the Euclidean distance using the Python built-in function `math.dist(des_coordinates, actual_coordinates)`.</span>
<span class="sd"> The velocity values are also extracted from the custom message, collected in a list of dimension `window_size` with a default value of 10 (modifiable in the launch file). The average velocity is then computed as `average_vel_x = sum(vel_data) / min(len(vel_data), velocity_window_size)`.</span>
<span class="sd"> These computed values compose the response of the service.</span>
<span class="sd"> The `info_service.py` module is run by the launch file, and the service can be called using the command `rosservice call /info_service` in the terminal.</span>

<span class="sd"> </span>
<span class="sd">Service:</span>
<span class="sd"> /info_service</span>

<span class="sd">Subscriber:</span>
<span class="sd"> /pos_vel</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">rospy</span>
<span class="kn">from</span> <span class="nn">geometry_msgs.msg</span> <span class="kn">import</span> <span class="n">Point</span><span class="p">,</span> <span class="n">Pose</span><span class="p">,</span> <span class="n">Twist</span>
<span class="kn">from</span> <span class="nn">nav_msgs.msg</span> <span class="kn">import</span> <span class="n">Odometry</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">assignment_2_2023.msg</span>
<span class="kn">from</span> <span class="nn">assignment_2_2023.msg</span> <span class="kn">import</span> <span class="n">Vel</span>
<span class="kn">from</span> <span class="nn">actionlib_msgs.msg</span> <span class="kn">import</span> <span class="n">GoalStatusArray</span>
<span class="kn">from</span> <span class="nn">assignment_2_2023.srv</span> <span class="kn">import</span> <span class="n">info_service</span><span class="p">,</span> <span class="n">info_serviceResponse</span>

<div class="viewcode-block" id="get_distance_and_averagevelocity"><a class="viewcode-back" href="../../index.html#scripts.info_service.get_distance_and_averagevelocity">[docs]</a><span class="k">def</span> <span class="nf">get_distance_and_averagevelocity</span><span class="p">(</span><span class="n">msg</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Callback function for the subscriber to the topic /pos_vel.</span>
<span class="sd"> </span>
<span class="sd"> :param msg: custom message containing the actual position and velocity of the robot</span>
<span class="sd"> :param des_pos_x: desired position x</span>
<span class="sd"> :param des_pos_y: desired position y</span>
<span class="sd"> :type des_pos_x: float</span>
<span class="sd"> :type des_pos_y: float</span>
<span class="sd"> :param window_size: size of the window for the average velocity</span>
<span class="sd"> :type msg: assignment_2_2023.msg.Vel</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">global</span> <span class="n">success</span><span class="p">,</span> <span class="n">average_vel_x</span><span class="p">,</span> <span class="n">distance</span>

<span class="c1"># desired position </span>
<span class="n">des_x</span> <span class="o">=</span> <span class="n">rospy</span><span class="o">.</span><span class="n">get_param</span><span class="p">(</span><span class="s1">&#39;/des_pos_x&#39;</span><span class="p">)</span>
<span class="n">des_y</span> <span class="o">=</span> <span class="n">rospy</span><span class="o">.</span><span class="n">get_param</span><span class="p">(</span><span class="s1">&#39;/des_pos_y&#39;</span><span class="p">)</span>

<span class="c1"># actual position</span>
<span class="n">actual_x</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">pos_x</span>
<span class="n">actual_y</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">pos_y</span>

<span class="c1"># compute distance</span>
<span class="n">des_coordinates</span> <span class="o">=</span> <span class="p">[</span><span class="n">des_x</span><span class="p">,</span> <span class="n">des_y</span><span class="p">]</span>
<span class="n">actual_coordinates</span> <span class="o">=</span> <span class="p">[</span><span class="n">actual_x</span><span class="p">,</span> <span class="n">actual_y</span><span class="p">]</span>
<span class="n">distance</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">dist</span><span class="p">(</span><span class="n">des_coordinates</span><span class="p">,</span> <span class="n">actual_coordinates</span><span class="p">)</span>

<span class="c1"># compute linear average velocity</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">vel_x</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">vel_data</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">vel_x</span><span class="p">[</span><span class="o">-</span><span class="n">velocity_window_size</span><span class="p">:]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">vel_data</span> <span class="o">=</span> <span class="p">[</span><span class="n">msg</span><span class="o">.</span><span class="n">vel_x</span><span class="p">]</span>

<span class="n">average_vel_x</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">vel_data</span><span class="p">)</span> <span class="o">/</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">vel_data</span><span class="p">),</span> <span class="n">velocity_window_size</span><span class="p">)</span></div>

<div class="viewcode-block" id="get_values"><a class="viewcode-back" href="../../index.html#scripts.info_service.get_values">[docs]</a><span class="k">def</span> <span class="nf">get_values</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Callback function for the service /info_service. Returns the distance from the goal and the average velocity of the robot.</span>
<span class="sd"> </span>
<span class="sd"> :param s: service request</span>
<span class="sd"> :type s: assignment_2_2023.srv.info_serviceRequest</span>
<span class="sd"> :return: service response containing the distance from the goal and the average velocity of the robot</span>
<span class="sd"> :rtype: assignment_2_2023.srv.info_serviceResponse</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">global</span> <span class="n">average_vel_x</span><span class="p">,</span> <span class="n">distance</span>

<span class="n">rospy</span><span class="o">.</span><span class="n">loginfo</span><span class="p">(</span><span class="s2">&quot;Distance= </span><span class="si">%f</span><span class="s2"> Average velocity = </span><span class="si">%f</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">average_vel_x</span><span class="p">)</span>
<span class="k">return</span> <span class="n">info_serviceResponse</span><span class="p">(</span><span class="n">distance</span><span class="p">,</span> <span class="n">average_vel_x</span><span class="p">)</span> </div>

<div class="viewcode-block" id="info_service_main"><a class="viewcode-back" href="../../index.html#scripts.info_service.info_service_main">[docs]</a><span class="k">def</span> <span class="nf">info_service_main</span><span class="p">():</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Initializes the node info_service.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">global</span> <span class="n">velocity_window_size</span>

<span class="n">rospy</span><span class="o">.</span><span class="n">init_node</span><span class="p">(</span><span class="s1">&#39;info_service&#39;</span><span class="p">)</span>
<span class="n">rospy</span><span class="o">.</span><span class="n">loginfo</span><span class="p">(</span><span class="s2">&quot;Info service node initialized&quot;</span><span class="p">)</span>

<span class="c1"># Read window size from the parameter server (set in the launch file)</span>
<span class="n">velocity_window_size</span> <span class="o">=</span> <span class="n">rospy</span><span class="o">.</span><span class="n">get_param</span><span class="p">(</span><span class="s1">&#39;/window_size&#39;</span><span class="p">)</span>

<span class="c1"># SUBSCRIBER: Subscribe to the custom message</span>
<span class="n">subscriber</span> <span class="o">=</span> <span class="n">rospy</span><span class="o">.</span><span class="n">Subscriber</span><span class="p">(</span><span class="s2">&quot;/pos_vel&quot;</span><span class="p">,</span> <span class="n">Vel</span><span class="p">,</span> <span class="n">get_distance_and_averagevelocity</span><span class="p">)</span>

<span class="c1"># SERVICE: Service to get the interested values</span>
<span class="n">service</span> <span class="o">=</span> <span class="n">rospy</span><span class="o">.</span><span class="n">Service</span><span class="p">(</span><span class="s2">&quot;info_service&quot;</span><span class="p">,</span> <span class="n">info_service</span><span class="p">,</span> <span class="n">get_values</span><span class="p">)</span>

<span class="n">rospy</span><span class="o">.</span><span class="n">spin</span><span class="p">()</span></div>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="n">info_service_main</span><span class="p">()</span>
</pre></div>

</div>
</div>
<footer>

<hr/>

<div role="contentinfo">
<p>&#169; Copyright 2024, Annika Delucchi.</p>
</div>

Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.


</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>

</body>
</html>
Loading

0 comments on commit 73a04fe

Please sign in to comment.