<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Faculty of Mathematics and Informatics, Sofia University St. Kliment Ohridski</institution>
          ,
          <addr-line>5 James Bourchier Blvd., 1164 Sofia</addr-line>
          ,
          <country country="BG">Bulgaria</country>
        </aff>
      </contrib-group>
      <fpage>89</fpage>
      <lpage>96</lpage>
      <abstract>
        <p>The field of robotics is experiencing rapid growth and is changing how we live our lives. Robotic systems are making their way into all areas of our life and by doing so present a number of challenges regarding safety. This is especially true in the fields of education and research where novel systems are being developed and tested. There are many articles focused on testing software systems in practice, but the same cannot be said about the testing of robotic systems. This paper aims to present such a study focused on the development and testing of a small balancing robot by analyzing the challenges of development, integration, and testing of the system. A series of steps that can be used to methodically test the components of a system and to verify that the desired functionality is implemented correctly are also proposed.</p>
      </abstract>
      <kwd-group>
        <kwd>Robotics</kwd>
        <kwd>Control Systems</kwd>
        <kwd>Testing Methods</kwd>
        <kwd>Real-Time</kwd>
        <kwd>Balancing Robot</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>The field of robotics is experiencing rapid growth and has the potential of
revolutionizing how we live our lives. The introduction of low-cost sensors,
actuators and other electrical components gives individuals, schools, universities,
and research labs the opportunity to experiment more and to contribute to this field.</p>
      <p>Companies such as Sparkfun, Adafruit, Pololu and many others provide
plug-and-play components with powerful features, that users can easily
incorporate into their projects. Even though most of these components are easy to use,
to get the most out of them, a certain degree of technical knowledge is required.</p>
      <p>A good example of this is sensor fusion and how it can be used to combine
data from an accelerometer and gyroscope to calculate the inclination angle of
the sensor.</p>
      <p>Another example is the use of PID algorithms to control robots. This is part
of the field of control theory, and it is an essential part of a variety of projects.</p>
      <p>In most cases, the algorithms mentioned above are implemented from scratch
and to determine if they work correctly, a testing approach needs to be considered.</p>
      <p>This paper covers the challenges of developing and testing a small robotic
system in practice and proposes a series of steps that can be used for testing other
small robotic systems.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Testing in the field of Robotics</title>
      <p>
        Robotic systems are heavily used in safety-critical domains such as healthcare,
education, and transportation. This increase in interaction between the public
and robotic systems drastically raises the chance of catastrophic failure [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. This
heightened risk makes testing of robotic systems a key part of the development
process. It is imperative that Cyber-Physical Systems (CPS) [
        <xref ref-type="bibr" rid="ref5 ref6 ref7">5-7</xref>
        ], of which
robotic systems may be considered a subcategory [
        <xref ref-type="bibr" rid="ref4 ref8">4, 8</xref>
        ] be thoroughly tested
before being used in production environments.
      </p>
      <p>
        Characteristics of robotic systems such as interaction with the physical world,
and integration of hardware and software components, differentiate robotic systems
from conventional software systems [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. Due to these inherent differences testing
approaches used for software cannot be directly applied to robotic systems.
      </p>
      <p>
        The main differences between software systems and robotic systems are: (1)
Robots are comprised of (unreliable and non-determinstic) hardware, software,
and physical components [
        <xref ref-type="bibr" rid="ref10 ref11 ref9">9-11</xref>
        ]. This applies to both hobby grade and industrial
grade products, but it is especially true when working with inexpensive
components in a research or education setting. (2) Robots interact with the physical
world via inherently noisy sensors and actuators and are sensitive to timing
differences [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]. (3) Robots operate within the practically boundless state space of
reality, making emergent behaviors (i.e., corner cases) difficult to predict [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]. (4)
For robotic systems, the notion of correctness is often inexact and difficult to
precisely specify [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
      <p>
        These differences introduce numerous challenges related to the testing of
robotic systems such as having to create heavy abstractions of physical reality
or conduction real-world field testing [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] that can be time-consuming and
expensive. In some cases, real-world testing may even be impossible because the
environments that the system is aim towards are difficult to access. Examples of
such environments are deep in the ocean, or on other planets.
      </p>
      <p>
        There are a lot of studies focused on software testing practices, however
none of them focus on the challenges in robotics [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. To address this lack of
research, a recent study interviewed a group of professionals working in the field of
robotics [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. The goal of this study was to identify common testing approaches,
the challenges that are commonly encountered when developing tests for robots
and the difficulties automating those tests.
      </p>
      <p>
        The methods of testing mentioned by the participants are: (1) Field Testing,
(2) Logging and playback, (3) Simulation Testing, (4) Plan-based testing and
(5) Compliance testing.[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] Out of these testing methods, simulation is one of
the most seldom used, as simulators that accurately simulate the real world to a
high degree just do not exist and are not suitable for testing of the whole system.
Simulation is usually used as a high-level development tool [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>
        The main challenges outlined in the study are: (1) Unpredictable corner
cases, (2) Engineering complexity, (3) Culture of testing and (4) Coordination,
collaboration, and documentation. [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]
      </p>
      <p>The last thing the study discusses are the challenges of automating tests. As
the previous paragraphs outline, testing on its own is difficult and trying to
automate it makes things even more tricky. The main difficulties are: (1) Cost and
resources, (2) Environmental complexity, (3) Distrust of simulation, (4) Software
and hardware integration.</p>
      <p>Due to all the outlined challenges, the area of robotic testing is still
developing and further research into practical testing approaches is required.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Case study architecture</title>
      <p>
        This section will briefly discuss the architecture of the system described in
this case study – the Teensy Balance Bot. Robots of this type share some key
characteristics, but there are many ways of implementing a balancing robot [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ],
because of this the specific architecture used for this case study is discussed.
      </p>
      <sec id="sec-3-1">
        <title>3.1 Hardware</title>
        <p>The Teensy Balance Bot, as the name suggests is based on the Teensy
microcontroller family, in this case a Teensy 4.1 is used. The IMU module is the
LSM6DS33 from Pololu, it has a gyroscope and accelerometer. The motor driver
is the Cytron MDD3A and the motors are generic brushed motors with reduction
gears. Two magnetic encoders from Pololu are used for detecting wheel rotation.
A small OLED screen is displays status messages. The robot is powered by two
Panasonic NCR18650PF Li-ion. The main body of the robot is custom made to
fit the parts and manufactured using 3D printing.</p>
        <p>The circuit diagram of the robot shows the connection between all the
components (see Fig. 1).</p>
      </sec>
      <sec id="sec-3-2">
        <title>3.3 Software</title>
        <p>The software that runs on the Teensy microcontroller is written in C++ and uses
a screen library from Adafruit. Everything else is built from scratch. Fig. 2 shows
the complete architecture.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Proposed testing approach</title>
      <p>Considering the challenges outlined in section 3, this section this section proposes
a testing method that provides a systematic approach for testing robotic systems
that fall into the category of balancing robots. Such robots are used in research
and education and are an excellent way of learning how to work with sensors and
actuators.</p>
      <p>It is possible using this process to verify easily that the robot is working
correctly, and that the desired functionality has been implemented.</p>
      <sec id="sec-4-1">
        <title>4.1 Feasibility study</title>
        <p>The testing phase of the project begins before any physical or software components
are created. MATLAB and Simulink are a good option for simulating robotic
systems.</p>
        <p>
          Using a simulation allows for early detection of potential defects and in cases
such as the balancing robot it helps to prove that the system can be created and
controlled from a mathematical point of view. Simulations also allow for
software to be tested before the hardware is available [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ].
        </p>
        <p>Using more advanced simulations and a more detailed model can also aid
in the development of the software that runs on the microcontroller, however as
section 3 outlined using simulation can be unreliable and refining the simulation
can be expensive. In the case of the Teensy Balance Bot, a simulation was used to
determine if the PID controller design was appropriate.</p>
      </sec>
      <sec id="sec-4-2">
        <title>4.2 Testing tools</title>
        <p>The next important step in this approach is choosing the right tools for testing.
Since both hardware and software tests are being performed, appropriate
equipment needs to be used.</p>
      </sec>
      <sec id="sec-4-3">
        <title>Software testing tools</title>
        <p>Software testing can be accomplished using the Visual Studio IDE with the
VisualMicro plugin. This combination allows for debugging and provides an easy
way to monitor the serial output from the microcontroller.</p>
      </sec>
      <sec id="sec-4-4">
        <title>Hardware testing tools</title>
        <p>An oscilloscope is used for verifying that the signals being sent from the
sensors to the microcontroller or vice versa are correct. Oscilloscopes are an
essential tool for testing as they are a window into the invisible world of electronics
and troubleshooting a complex system like a robot without one, while possible,
would be very difficult.</p>
      </sec>
      <sec id="sec-4-5">
        <title>4.3 Divide and Conquer</title>
        <p>Divide and Conquer is a popular strategy that is used in many fields. It is of
particular interest in the testing of robotic systems because it allows for early
problem detection and correction. Robots are made up of many components
and diagnosing issues as a single system is difficult. Due to this, the approach
proposed in this paper examines the case where each component goes through
three stages:</p>
        <p>
          Initial prototype – During this phase only basic functionality is developed
and tested. Additional care is taken to not crowd the code with unnecessary
functionality and the hardware is limited to the basic components. A good example
of this is the development of the inclination angle measurement component. The
first step in the development of this component is to validate that the IMU is
function and producing data. The second step is to convert the raw data into a known
unit and to verify that the values are correct. The third step is to implement a
sensor fusion algorithm such as a Complementary or Kalman filter to measure an
inclination angle [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ].
        </p>
        <p>Defining component I/O – In this step the inputs and outputs of the
component are defined. This part embraces the black box model and allows for a good
level of modularity. A key property of the approach proposed in this paper is
modularity, even in the smallest projects, as it allows for much more flexibility.</p>
        <p>Creating final version – During this phase, the component is implemented
using best practices and conventions.</p>
        <p>The three steps listed above are aimed towards software components that
interact with hardware, such as sensors, as well as those that work exclusively
with software components.</p>
        <p>
          The “Divide and Conquer” approach falls into the category of Plan-based
testing, outlined in section 3. It involves creating a rough plan and objectives for
testing that can be specified in advance to manage and guide testing [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ]. The
participants in the study mentioned that they create system requirements list, which
is used to ensure all components of the system are covered by the tests [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ].
        </p>
      </sec>
      <sec id="sec-4-6">
        <title>4.4 Final tests</title>
        <p>Final tests of the system are the last step in this approach. In this phase, processes
such as PID tuning are performed to dial in the behavior of the robot. PID tuning
is done by varying the PID gains that are used in the algorithm, there are two
main ways of accomplishing this. Before tuning a PID controller it is necessary
to examine how each gain affects the behavior of the system.</p>
        <p>
          As the name suggests, there are 3 gains to be tuned. “The proportional (P)
action gives a change in the input (manipulated variable) directly proportional to
the control error. The integral (I) action gives a change in the input proportional
to the integrated error, and its main purpose is to eliminate offset. The less
commonly used derivative (D) action is used in some cases to speed up the response
or to stabilize the system, and it gives a change in the input proportional to the
derivative of the controlled variable. The overall controller output is the sum of
the contributions from these three terms.” [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ].
        </p>
        <p>The two methods of tuning a PID controller examined in this paper are using
the system model together with built-in MATLAB functionality to calculate the
gains and empirical testing.</p>
        <p>Using results from the simulation. MATLAB has a useful feature that
analyzes the model of the system and generates the appropriate PID gains
automatically. This is a very quick and precise way to tune the system. The only downside
to this method is that if the model that is being used is not accurate enough, the
PID gains might not work well when used on the physical system.</p>
        <p>Another approach is empirical testing. This is a more time-consuming
approach, but it is easy for anyone to perform and it delivers good results. Empirical
testing starts by setting the I and D gains to 0 and the P to 1. The P gain is then
increased until the system oscillates, in the case of a balancing robot this means
that the robot tilts back and forth. After that point, the P gain is decreased, and the
D gain is increased. The D (derivative) gain has a damping effect that stabilizes
the system. The last gain to be dialed in is the I gain; this affects the steady state
error and should be implemented carefully to avoid integrator windup.</p>
        <p>With the steps described above it is possible to easily tune a PID controller.
This technique is suitable for small robots such as the Teensy Balance Bot or
other projects used in research and education because during the tuning process
the effects of each gain can be easily observed.</p>
        <p>This testing approach falls into the category of “Field testing” outlined in
section 3. In the same study, participants mentioned that during testing they relied
on intuition to judge if something is working correctly or not. For the case of a
small balancing robot, tuning the PID controller by testing it in the real world
and using intuition to judge if the robot is performing correctly is a good way of
efficiently testing the system.</p>
        <p>More formal ways of testing such as using a simulation will always deliver
better results, but as mentioned in section 3, simulations can be unreliable and
might not replicate the real world correctly and that will lead to incorrect results.
More time can be spent to refine the simulation, but for such a simple case as a
balancing robot the cost of creating a detailed simulation is not justified.
5</p>
      </sec>
      <sec id="sec-4-7">
        <title>Conclusion</title>
        <p>The case study of a balancing robot discussed in this paper is a typical example of
how a PID controller is designed, implemented, and tested for a real-world system.
The paper proposes a simple, but powerful modular approach to robot testing, that
can be used in education or research settings. The presented approach gives insight
into a practical implementation of the testing method by showcasing the testing
steps of a balancing robot. Two PID testing approaches are discussed. In cases
where field testing is an option an intuitive PID tuning approach that enables rapid
testing and development of robots in research or education is outlined. In cases
where testing the PID controller on a physical system is impractical, a simulation
approach with both advantages and disadvantages is discussed.
6</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments</title>
      <p>This work has been accomplished with the financial support by the Grant №
BG05M20P001-1.002-0011, financed by the Science and Education for Smart
Growth</p>
      <p>Operational Program (2014-2020) and co-financed by the European Union
through the European structural and Investment funds.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Skogestad</surname>
          </string-name>
          , Sigurd. (
          <year>2001</year>
          ).
          <article-title>Probably the best simple PID tuning rules in the world</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Hau-Shiue</surname>
          </string-name>
          , Juang &amp; Lum, Kai-Yew.
          <article-title>(</article-title>
          <year>2013</year>
          ).
          <article-title>Design and control of a two-wheel self-balancing robot using the arduino microcontroller board</article-title>
          .
          <volume>634</volume>
          -
          <fpage>639</fpage>
          .
          <fpage>10</fpage>
          .1109/ICCA.
          <year>2013</year>
          .
          <volume>6565146</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>J.</given-names>
            <surname>Conradt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Cook</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Berner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Lichtsteiner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. J.</given-names>
            <surname>Douglas</surname>
          </string-name>
          and
          <string-name>
            <given-names>T.</given-names>
            <surname>Delbruck</surname>
          </string-name>
          , “
          <article-title>A pencil balancing robot using a pair of AER dynamic vision sensors</article-title>
          ,”
          <source>2009 IEEE International Symposium on Circuits and Systems</source>
          , Taipei, Taiwan,
          <year>2009</year>
          , pp.
          <fpage>781</fpage>
          -
          <lpage>784</lpage>
          , doi: 10.1109/ISCAS.
          <year>2009</year>
          .
          <volume>5117867</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>A.</given-names>
            <surname>Afzal</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C. L.</given-names>
            <surname>Goues</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Hilton</surname>
          </string-name>
          and
          <string-name>
            <given-names>C. S.</given-names>
            <surname>Timperley</surname>
          </string-name>
          , “
          <source>A Study on Challenges of Testing Robotic Systems,” 2020 IEEE 13th International Conference on Software Testing, Validation and Verification (ICST)</source>
          ,
          <year>2020</year>
          , pp.
          <fpage>96</fpage>
          -
          <lpage>107</lpage>
          , doi: 10.1109/ICST46399.
          <year>2020</year>
          .
          <volume>00020</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Duan</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          et al. “
          <article-title>A Systematic Mapping Study on the Verification of Cyber-Physical Systems</article-title>
          .” IEEE Access 6
          <article-title>(</article-title>
          <year>2018</year>
          ):
          <fpage>59043</fpage>
          -
          <lpage>59064</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>S. A.</given-names>
            <surname>Seshia</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Hu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Li</surname>
          </string-name>
          ,
          <string-name>
            <given-names>and Q.</given-names>
            <surname>Zhu</surname>
          </string-name>
          , “
          <article-title>Design automation of cyber-physical systems: Challenges, advances</article-title>
          , and opportunities,
          <source>” IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems</source>
          , vol.
          <volume>36</volume>
          , no.
          <issue>9</issue>
          , pp.
          <fpage>1421</fpage>
          -
          <lpage>1434</lpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>D.</given-names>
            <surname>Marijan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Gotlieb</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M. K.</given-names>
            <surname>Ahuja</surname>
          </string-name>
          , “
          <article-title>Challenges of testing machine learning based systems</article-title>
          ,” in
          <source>International Conference On Artificial Intelligence Testing</source>
          , ser.
          <source>AITest'19. IEEE</source>
          ,
          <year>2019</year>
          , pp.
          <fpage>101</fpage>
          -
          <lpage>102</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>S. K.</given-names>
            <surname>Khaitan and J. D. McCalley</surname>
          </string-name>
          , “
          <article-title>Design techniques and applications of cyberphysical systems: A survey,” IEEE Systems Journal</article-title>
          , vol.
          <volume>9</volume>
          , no.
          <issue>2</issue>
          ,pp.
          <fpage>350</fpage>
          -
          <lpage>365</lpage>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>L.</given-names>
            <surname>Esterle</surname>
          </string-name>
          and
          <string-name>
            <given-names>R.</given-names>
            <surname>Grosu</surname>
          </string-name>
          , “
          <article-title>Cyber-physical systems: challenge of the 21st century,” e &amp; i Elektrotechnik und Informationstechnik</article-title>
          , vol.
          <volume>133</volume>
          , no.
          <issue>7</issue>
          , pp.
          <fpage>299</fpage>
          -
          <lpage>303</lpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>C. Hutchison</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Zizyte</surname>
            ,
            <given-names>P. E.</given-names>
          </string-name>
          <string-name>
            <surname>Lanigan</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Guttendorf</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Wagner</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          <string-name>
            <surname>Le Goues</surname>
            , and
            <given-names>P.</given-names>
          </string-name>
          <string-name>
            <surname>Koopman</surname>
          </string-name>
          , “
          <article-title>Robustness testing of autonomy software</article-title>
          ,” in International Conference on Software Engineering: Software
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <given-names>H.</given-names>
            <surname>Li</surname>
          </string-name>
          ,
          <article-title>Communications for control in cyber physical systems: theory, design and applications in smart grids</article-title>
          . Morgan Kaufmann,
          <year>2016</year>
          , ch. 1
          <article-title>-Introduction to cyber physical systems</article-title>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>