Skip to content

SSL-Roots/FrootsPi_ros

Repository files navigation

Build Status

FrootsPi

ROS packages on Raspberry Pi for RoboCup SSL Robot

Raspberry Pi + Roots -> Fruits(Raspberry) Pi + Roots -> FrootsPi 👍

Project Status

  • Create this repository
  • Create hello world code
  • Create simple node test code
  • Create simple library test code
  • Simple travis-ci test succeeded
  • Create blank ROS packages
  • Each ROS nodes' test succeeded
  • Integrated tests succeeded
  • FrootsPi robot power on
  • FrootsPi robot correctly moved! :)

Requirements

  • Device
    • Raspberry Pi 3 model B/B+
  • OS
    • Ubuntu 16.04
    • Raspbian (Untested)
  • ROS
    • Kinetic
  • and SSL Robot parts
    • Our team's mechanic / electric cad data here -> ( )

Installation

ROS Install

Ganbatte!!!

FrootsPi Install

  $ git clone https://github.com/SSL-Roots/FrootsPi ~/catkin_ws/src/FrootsPi

  $ cd ~/catkin_ws
  $ catkin_make

Raspberry Pi Settings

You have to enable interfaces i2c, spi.

  $ sudo raspi-config

How to write test code

Node test

  1. Create tests directory to a package tree

Example: frootspi_hello_world

  .
  ├── CMakeLists.txt
  ├── package.xml
  ├── scripts
  └── tests
      └── test_hello_world.py
  1. Add a test code

Example: test_hello_world.py

  #!/usr/bin/env python
  #encoding: utf8

  import rospy, unittest, rostest
  import rosnode
  import time

  class HelloWorldTest(unittest.TestCase):
      def test_node_exist(self):
          nodes = rosnode.get_node_names()
          self.assertIn('/hello_world', nodes, 'node does not exist')


  if __name__ == '__main__':
      time.sleep(3) # テスト対象のノードが立ち上がるのを待つ
      rospy.init_node('test_hello_world.')
      rostest.rosrun('frootspi_hello_world', 'test_hello_world', HelloWorldTest)
  • This test code checks node existance
  1. Write a rostest file

Example: frootspi_core/tests/test_frootspi.test

  <launch>
      <node name="hello_world" pkg="frootspi_hello_world" type="hello_world.py" required="true" />
      <test test-name="test_hello_world" pkg="frootspi_hello_world" type="test_hello_world.py" />

  </launch>
  • If you create a new rostest file, you have to edit test_scripts/travis_script.bash to execute travis_ci test
  1. Run the rostest
  $ rostest frootspi_core test_frootspi.test

Library test

  1. Create tests directory to a scripts directory

Example: frootspi_hello_world

  .
  ├── CMakeLists.txt
  ├── package.xml
  ├── scripts
  │   ├── hello_world.py
  │   ├── tests
  │   │   └── test_hello.py
  │   └── util
  │       ├── __init__.py
  │       └── hello.py
  1. Add a test code

Example library: util/hello.py

  #encoding: utf8

  def add_hello(text):
      return text + 'hello'

  def enclose_hello(text):
      return 'he' + text + 'llo'


  class Calculator(object):
      def __init__(self):

          self._buffer = None

      def add(self, a, b):
          return a + b

      def set_value(self, value):
          self._buffer = value

      def get_value(self):
          return self._buffer

      def delete_value(self):
          self._init_buffer()
          return True

      def _init_buffer(self):
          self._buffer = None

Example library test code: tests/test_hello.py

  #!/usr/bin/env python
  #encoding: utf8

  import sys, os
  import unittest

  pardir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  sys.path.append(pardir)

  import util.hello as hello

  class TestHello(unittest.TestCase):

      def setUp(self):
          self._calculator = hello.Calculator()


      def test_add_hello(self):
          expected = "abcdehello"
          result = hello.add_hello("abcde")
          self.assertEqual(expected, result)


      def test_enclose_hello(self):
          expected = "heabcdello"
          result = hello.enclose_hello("abcde")
          self.assertEqual(expected, result)


      def test_add(self):
          expected = 3
          result = self._calculator.add(1, 2)
          self.assertEqual(expected, result)

          expected = 2.5
          result = self._calculator.add(1.7, 0.8)
          self.assertAlmostEqual(expected, result)


      def test_set_value(self):
          value = 4
          self._calculator.set_value(value)

          result = self._calculator.get_value()
          self.assertEqual(value, result)


      def test_delete_value(self):
          self._calculator.set_value(2.4)
          self._calculator.delete_value()

          expected = None
          result = self._calculator.get_value()
          self.assertEqual(expected, result)


  if __name__ == "__main__":
      import rosunit
      rosunit.unitrun('frootspi_hello_world', 'test_hello', TestHello)
  1. Edit a CMakeLists.txt

Example: frootspi_hello_world/CMakeLists.txt

  ...
  catkin_add_nosetests(scripts/tests/test_hello.py)
  1. Run the rostest
  # Run the all tests
  $ cd ~/catkin_ws
  $ catkin_make run_tests 
  
  # Get result
  # Caution! `catkin_make run_tests` always returns 0
  $ catkin_test_results
  
  # Run arbitary test
  $ cd ~/catkin_ws
  $ catkin_make run_tests_frootspi_hello_world_nosetests_scripts.tests.test_hello.py

References

Author

Roots : A RoboCup SSL team on Japan -> Roots Home

About

ROS packages on Raspberry Pi for RoboCup SSL Robot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published