Skip to content

Development guidelines

jaxa edited this page Nov 30, 2020 · 4 revisions

ROS/cFE Project development guidelines

Revision history

Revision date of issue Contents
1.0 7/7/2020 First edition

Table of Contents

[[TOC]]

1. General rules

1.1. Purpose

This document describes the guidelines for ROS application development when developing software using the ROS/cFE conversion module.

1.2. Scope

The ROS/cFE conversion module is a conversion module for building a system by incorporating a ROS application using cFE as a platform. This document defines guidelines for developing ROS applications.

2. Term definitions

The terms used in this guideline are defined below.

Table 2-1 Definition of terms

Term Description
ROS Abbreviation for Robot OS. One of middleware for robots.
node Software components created with ROS.
topic Data communicated between ROS nodes
package A collection of ROS nodes in functional units
cFE Abbreviation for Core Flight Executive. Open source middleware for spacecraft created by NASA Goddard Space Flight Center.
OSAL Abbreviation for OS Abstraction Layer. The lower part of the OS-dependent part of cFE.

3. ROS application development environment for cFE

3.1. Operating environment

The operating environment of ROS and cFE application is shown in this chapter.

3.1.1. Ubuntu

This document shows the building procedure in the environment where Ubuntu 16.04 LTS is installed. The required libraries are shown below.

  • gcc-multilib
  • g ++-multilib
  • build-essential
  • libc-dev-i386
  • libstdc ++ 6-4.7-dev: i386

3.1.2. ROS

The version of ROS used is kinetic or melodic.

3.1.3. CFE

3.1.3.1. OSAL

Version 4.2.1 is used for OSAL. OSAL is downloaded from the following URL. Https://sourceforge.net/projects/osal/files/osal-4.2.1a-release.tar.gz/download

3.1.3.2. CFE source code

Version 6.5.0 of the cFE source code is used. Download cFE source code from the following URL. Https://sourceforge.net/projects/coreflightexec/files/cFE-6.5.0/

3.1.4. Development language

The development language is C ++.

3.2. Environment construction

3.2.1. ROS environment construction procedure

3.2.1.1. ROS kinetic

The procedure for installing ROS kinetic is shown below. Reference URL: http://wiki.ros.org/kinetic/Installation/Ubuntu

Execute the following command.

# sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# sudo apt-key adv --keyserver 'hkp://ha.pool.sks-keyservers.net:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
# sudo apt update
# sudo apt install ros-kinetic-desktop-full

Execute the following command to configure ROS.

# echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
# source ~/.bashrc

Execute the following command to perform rosinstall order.

# sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
# sudo apt-get install python-rosinstall
# sudo rosdep init
# rosdep update
3.2.1.2. ROS melodic

The procedure for installing ROS melodic is shown below. Reference URL: http://wiki.ros.org/melodic/Installation/Ubuntu

Execute the following command.

# sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
# sudo apt update
# sudo apt install ros-melodic-desktop-full

Execute the following command to configure ROS.

# echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
# source ~/.bashrc

Execute the following command to perform rosinstall order.

# sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
# sudo apt install python-rosdep
# sudo rosdep init
# rosdep update

3.2.2. CFE environment construction procedure

Download the OSAL and cFE source code from the URL shown in Chapter 3.1.3.1 and 3.1.3.2 and execute the following command.

# tar -zxf cFE-6.5.0-OSS-release.tar.gz
# tar -zxf osal-4.2.1-release.tar.gz
# mv osal-4.2.1-release cFE-6.5.0-OSS-release /osal

4. ROS/cFE conversion module supported

4.1. ROS function

The list of ROS functions to be ported is shown below.

Table 4-1 ROS function portability list

No. Function name Portability Remarks
1. Publish
2. Subscribe
3. Service × incompatible
4. Action × incompatible
5. Param Future support
6. Bag Future support

4.2. ROS function

The ROS functions supported by the ROS/cFE conversion module are shown below.

Table 4-2 List of supported functions

guid_table4-2

4.3. Topic / Message Type

The topic / message types supported by the ROS/cFE conversion module are shown below.

Table 4-3 Supported topics / message types

guid_table4-3

4.4. ROS Package

The ROS package supported by the ROS/cFE conversion module is only part of tf. The supported tf package files are shown below.

Table 4-4 List of supported tf package files

No. tf file name Class name
1. Matrix3x3.h Matrix3x3
2. MinMax.h -
3. QuadWord.h QuadWord
4. Quaternion.h Quaternion
5. Scalar.h -
6. StampedTransform.h StampedTransform
7. Transform.h Transform
8. Vector3.h Vector3

4.5. Coding Practice Notes

The precautions when describing the ROS code are shown below.

① Do not indent global variable and global function definitions
② Do not place multiple source codes with a main statement in a ROS node
③ Separate the definition of Publisher and Subscriber from advertise / subscribe

Example)

# Conversion error
ros::Publisher ros_pub = n.advertise<std_msgs::Header>("ros_cfe_msg", 1000);

# Convertible
ros::Publisher ros_pub;
ros_pub = n.advertise<std_msgs::Header>("ros_cfe_msg", 1000); 

④ Place parentheses in function definitions at the beginning of a line

[Reference] ROS cpp coding style guide
http://wiki.ros.org/CppStyleGuide

4.6. Sample code

ROS sample nodes that publish and subscribe are described below.

  • sample_pub.h

    #ifndef _SAMPLE_PUB_
    #define _SAMPLE_PUB_
    #include <ros/ros.h>
    #include <std_msgs/Header.h>
    #endif // _SAMPLE_PUB_
    
  • sample_pub.cpp

    #include "sample_pub/sample_pub.h"
    int main(int argc, char** argv)
    {
        ros::init(argc, argv, "sample_pub");
        ros::NodeHandle nh;
        ros::Publisher ros_pub;
        ros_pub = nh.advertise<std_msgs::Header>("ros_cfe_msg", 100);
        ros::Rate loop_rate(100);
        int count = 0;
        while(ros::ok())
        {
            std_msgs::Header msg;
            msg.seq = count;
            ROS_INFO("send msg.data: %d, rostimenow.toSec: %f", msg.seq, ros::Time::now().toSec());
            ros_pub.publish(msg);
            loop_rate.sleep();
            count++;
        }
        return 0;
    }
    
  • sample_sub.h

    #ifndef _SAMPLE_SUB_
    #define _SAMPLE_SUB_
    #include <ros/ros.h>
    #include <std_msgs/Header.h>
    #endif // _SAMPLE_SUB_
    
  • sample_sub.cpp

    #include "sample_sub/sample_sub.h"
    void msgCallback(const std_msgs::Header::ConstPtr& msg)
    {
        ROS_INFO("received data: %d", msg->seq);
    }
    int main(int argc, char** argv)
    {
        ros::init(argc, argv, "sample_sub");
        ros::NodeHandle nh;
        ros::Subscriber ros_sub;
        ros_sub = nh.subscribe<std_msgs::Header>("ros_cfe_msg", 100, msgCallback);
        ros::spin();
        return 0;
    }
    

4.7. Special notes

The ROS node to be developed here is assumed to be embedded software to be mounted on a spacecraft, so the mounting environment is limited by the special environment. Here, the restrictions are described.

4.7.1. Compiler

Older versions of compilers are often used in embedded software development environments. In C / C ++, it is often at the C99 level. When developing a ROS node, using an older version such as C99 instead of the latest compiler facilitates conversion to the ROS/cFE conversion module environment.

4.7.2. Stack size

Although the ROS node running on LinuxPC is almost unaware of the stack size, the amount of memory that can generally be used in embedded environments is small (several tens to hundreds of kilobytes). For this reason, memory destruction or the like will occur unless implemented with consideration for the stack amount. It should be noted that the implementation is as follows.

  1. Do not declare large class objects, arrays, etc. as local variables. Allocate memory in the heap area with new or malloc.
  2. Do not pass large-sized class objects, arrays, etc. to functions by value. Pass by reference.

4.7.3. Standard Output

Usually, the embedded software operates in an environment without a display or the like, and thus rarely uses the standard output. For this reason, libraries in the embedded development environment may not include those related to standard output. Use the following method to use the standard output only when debugging or developing on a Linux PC.

  • Implementation example 1: Surround the standard output part with #ifdef, and comment out the compile option in the embedded environment.
  • Implementation example 2: Create two standard output functions, one for debugging and one for embedded environment, and replace them with the development environment.

4.7.4. Libraries

Compared to Linux PCs, the operating environment of embedded software has extremely low performance such as CPU clock and memory capacity. For this reason, high-performance libraries are rarely used (linking a large library increases the amount of memory). Therefore, even in a development environment, even in a Linux environment, even a library such as a general STL cannot be used in many cases. It is recommended to implement using basic functions as much as possible. If the operating environment and development environment have been determined, investigate that environment and investigate available libraries in advance.

4.7.5. Topic Name

Avoid publish / subscribe using the same topic name within one ROS node. In that case, change to a different topic name and modify other ROS nodes.

5. ROS code build

Refer to the operation manual for the building procedure.

6. ROS/cFE conversion module management and provision policy

Regarding version upgrades, either ROS or cFE shall make any changes that affect the development of spacecraft software. At the time of version upgrade, the policy is to make it backward compatible.

7. References

  1. ROS http://wiki.ros.org/

  2. cFE https://opensource.gsfc.nasa.gov/projects/cfe/index.php