22

Google's Rosjava Framework With Android and Java

Embed Size (px)

Citation preview

Page 1: Google's Rosjava Framework With Android and Java
Page 2: Google's Rosjava Framework With Android and Java
Page 3: Google's Rosjava Framework With Android and Java
Page 4: Google's Rosjava Framework With Android and Java
Page 5: Google's Rosjava Framework With Android and Java
Page 6: Google's Rosjava Framework With Android and Java
Page 7: Google's Rosjava Framework With Android and Java

A BRIEF ABOUT rosjava FRAMEWORK

rosjava is a pure Java implementation of ROS(Real-Time Operating System) for ANDRO-HUMANOID ROBOTS. It provides a client library that enables Java programmers to quickly interface with ROS Topics, Services, and Parameters. Using rosjava is ideal when you need to:

Interact with prior Java programs or libraries.

Write Android apps that work with ROS.

It also provides a Java implementation of roscore, which is a collection of nodes and programs that are pre-requisites of a ROS-based system. You must have roscore running in order for ROS nodes to communicate. It is launched using the roscore command.

roscore will startup:

a ROS Master

a ROS Parameter Server

a rosout logging node

JNI BASED IMPLEMENTATION OF rosjava

rosjava is a partial implementation of the ROS NodeHandle API for Java. The current implementation works by calling roscpp behind the scenes using JNI, although the intention is to eventually rewrite it purely in Java.

The interfaces in the “ros” package are intended to be independent of the implementation, so that this change can be made transparently when the pure Java implementation has been written.

OUTLINE OF ANDROID OS

Android is an operating system developed mainly for mobile phones and tablet PC’s. It had become emerged into world with various apps for mobile phones like smart phones etc. Android consists of a kernel based on Linux Kernel, with middleware, libraries and APIs written in C and application software running on an application framework which includes Java-compatible libraries based on Apache Harmony.

Android uses the Dalvik Virtual Machine with Just-In- Time compilation to run Dalvik dex-code(Dalvik Executable), which is usually transferred from Java bytecode.

Page 8: Google's Rosjava Framework With Android and Java

JAVA SUPPORT IN ANDROID BASED SYSTEMS

While most Android applications are written in Java, there is no Java Virtual Machine in the platform and Java bytecode is not executed. Java classes are compiled into Dalvik executables and run on Dalvik, a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU. J2ME support can be provided via third-party applications.

A BRIEF ON DALVIK VIRTUAL MACHINE

Dalvik is the process virtual machine (VM) in Google's Android operating system. It is the software that runs the apps on Android devices. Dalvik is thus an integral part of Android, which is typically used on mobile devices such as mobile phones and tablet computers and now in humanoid robots.

Programs are commonly written in a dialect of Java and compiled to bytecode. Then they are converted from Java Virtual Machine-compatible .class files to Dalvik-compatible .dex (Dalvik Executable) files before installation on a device. The compact Dalvik Executable format is designed to be suitable for systems that are constrained in terms of memory and processor speed.

ARCHITECTURE

Unlike Java VMs, which are stack machines, the Dalvik VM is a register-based architecture.

A tool called "dx" is used to convert some (but not all) Java .class files into the .dex format.

Multiple classes are included in a single .dex file. Duplicate strings and other constants used in multiple class files are included only once

in the .dex output to conserve space. Java bytecode is also converted into an alternative instruction set used by the Dalvik

VM. An uncompressed .dex file is typically a few percent smaller in size than a compressed

.jar (Java Archive) derived from the same .class files

PERFORMANCE

Being optimized for low memory requirements, Dalvik has some specific characteristics that differentiate it from other standard VMs:

The VM was slimmed down to use less space The constant pool has been modified to use only 32-bit indices to simplify the

interpreter Standard Java bytecode executes 8-bit stack instructions. Local variables must be copied to or from the operand stack by separate instructions. Dalvik instead uses its own 16-bit instruction set that works directly on local variables. The local variable is commonly picked by a 4-bit 'virtual register' field. This lowers Dalvik's instruction count and raises its interpreter speed.

Page 9: Google's Rosjava Framework With Android and Java

Moreover, according to Google, Dalvik has been designed so that a device can run multiple instances of the VM efficiently.

Diagramatic Representation of Dalvik Architecture for ANDROID

What is an RTOS?

An RTOS is a class of operating systems that are intended for real time-applications. A real time application is an application that guarantees both correctness of result and the added constraint of meeting a deadline.

A BRIEF ABOUT RTOS

RTOS is an Operating System which follows the Real Time criteria. A system is said to be Real Time if it is required to complete it’s work & deliver it’s services on time. To be considered "real-time", an operating system must have a known maximum time for each of the operations that it performs (or at least be able to guarantee that maximum most of the time). Operating systems that can absolutely guarantee a maximum time for these operations are referred to as "hard real-time", while operating systems that can only guarantee a maximum most of the time are referred to as "soft real-time".

Page 10: Google's Rosjava Framework With Android and Java

Properties of an RTOS

Efficiency Predictability Timelessness

Linux for Real Time Applications

Scheduling

Priority Driven Approach-optimize average case response time. Interactive processes given highest priority-Aim to reduce response Real Time Processes-processes with high priority, no notion of deadlines.

Resource Allocation

No support for handling priority inversion

RTLinux

RTLinux is a Real Time Kernel which runs at lowest level. Linux kernel is a low priority thread that means executed only when no real time tasks. An RT system application can be divided into 2 parts. They are:-

Real Time task/process(Temporal Properties Important). Non-Real Time task/process(Temporal Properties not as important)

Ideology behind RTLinux

Extend the existing source to provide the standard functionalities at the same time provide a framework that can guarantee Hard Real Time requirements to be fulfilled.

Real Time Linux Approaches

The following three are the broader paradigms to solve RTOS problem:

Providing Non-real time services to the basic real time kernel.o Example – VxWorks.

Pre-emption improvement in Standard Kernel, that means pre-empting the patch for Linux kernel.

Virtual Machine Layer to make standard kernel Pre-emptable(RTLinux/RTAI).

Comparison of RTAI with RTLinux

Page 11: Google's Rosjava Framework With Android and Java

RTAI RTLinuxIt executes Real Time tasks in the kernel memory space preventing RT threads to be swapped out.

It executes Real Time tasks in the kernel memory space preventing RT threads to be swapped out.

Allocation of memory is of Dynamic type. RTLinux still uses static allocation type of memory.

Shared Memory(Linux<->RTLinux) is provided.

Shared Memory(Linux<->RTLinux) is provided.

IPC functions in RTAI are more extensive FIFO, Mailboxes, Message, net_rpc.

IPC functions in RTLinux are not much extensive.

RTAI does not provide user space real time signals.

RTLinux only provides user space real time signals. No interaction with RTservices or Linux System calls possible in those handlers.

RTLinux Architecture/Framework

Standard time sharing OS and hard real time executive running on same machine. Kernel provided with the emulation of Interrupt control hardware. RT tasks run at kernel privilege level to provide direct hardware access. RTLinux runs linux kernel for booting, device drivers, networking, FS, process control and loadable kernel modules. Linux kernel runs as a low priority task on the RT kernel hence making sure it cannot pre-empt any RT task. RT task allocated fixed memory for data and code. RT tasks cannot use Linux system calls,

Page 12: Google's Rosjava Framework With Android and Java

directly call routines or access ordinary data structures in Linux Kernel. RTProcesses without memory protection features. The RT kernel is actually patched over the Linux kernel and then recompiled to work as a RTLinux system.

RTLinux Internals

Interrupt Handling

Interrupt Handlers in RT executive perform whatever functions are required and passes interrupts to Linux. All Linux “wrappers” modified to fix stacks to cheat Linux to believe H/W interrupt and hence kernel mode execution ensured. S_IRET is used to save minimal state and look for pending interrupts (call other wrappers) otherwise restore registers and return from Interrupt.

Interrupt Handling APIs

rtl_request_irq() - Add RT Interrupt Handler

rtl_free_irq () – Remove RT Interrupt Handler

rtl_get_soft_irq ()- Install Software interrupt Handler

rtl_free_soft_irq ()- Remove Software interrupt Handler

rtl_global_pend_irq ()- Schedule a Linux Interrupt

RT-FIFO

This provides the primary mechanism through which the RTprocesses interact with the Linux processes. RT tasks should pre allocate the default size of FIFO and the number. RTKernel Config has options for–>

- Pre Allocated FIFO Buffer

- Max number of FIFO

Only one SIGPOLL handler installed at a given time.

Many fd share the same FIFO but only one SIGPOLL handler.

Example program for FIFO

Page 13: Google's Rosjava Framework With Android and Java

// Program in Linux writing to FIFO //rtf3 for Sound

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

#define DELAY 30000

void make_tone1(int fd)

{

static char buf = 0;

write (fd, &buf, 1);

}

void make_tone2(int fd)

{

static char buf = 0xff;

write (fd, &buf, 1);

}

main()

{

int i, fd = open ("/dev/rtf3", O_WRONLY);

while (1)

{

for (i=0;i<DELAY;i++);

make_tone1(fd);

for (i=0;i<DELAY;i++);

make_tone2(fd);

}}

Example for RT process

Page 14: Google's Rosjava Framework With Android and Java

// RT process doing the same work

#include <rtl.h>

#include <pthread.h>

#include <rtl_fifo.h>

#include <time.h>

#define FIFO_NO 3

#define DELAY 30000

pthread_t thread;

void * sound_thread(int fd)

{

int i;

static char buf = 0;

while (1)

{

for(i=0; i<DELAY; i++);

buf = 0xff;

rtf_put(FIFO_NO, &buf, 1);

for(i=0;i<DELAY;i++);

buf = 0x0;

rtf_put(FIFO_NO, &buf, 1);

}

return 0;

}

int init_module(void)

{

return pthread_create(&thread, NULL, sound_thread,

NULL);

Page 15: Google's Rosjava Framework With Android and Java

}

void cleanup_module(void)

{

pthread_delete_np(thread);

}

// Finally a kernel module that will be a RT thread and

// will read the char device //rtf3 to produce sound

Shared Memory

Almost the same principle it uses POSIX RT extensions

- shm_open(“file”,0_CREATE,0) // 0755 to allow Linux to use it

- shm_unlink()

- mmap() //Area created needs to be mapped

Reference Count

- Maintained so that shm_unlink() / unlink() don’t wipe out the resource in use across Linux or RTLinux processes.

Clocks & Timers

Clocks used to manage time in computers –Clocks control API’s

- Timers is H/w or S/w allow functions to be evoked at specified time in future.

- Multi task systems need timers for each one of them hence S/w timers used.

- Timer Interrupt will trigger task schedule at specified moments (One shit timers) – Timer management API support.

rtker - Our RTOS

We can develop our own OS by using rtker which is fully having grasping of source code that means which can be modifiable and portable.

Page 16: Google's Rosjava Framework With Android and Java

Features of rtker

Modular Design o Isolation of Architecture/CPU dependent and independent code – Easy to Port

Pluggable Scheduler. Two level Interrupt Handling. Small footprint. Oskit’s Device Driver Framework.

Interaction between rtker & Linux kernel

Page 17: Google's Rosjava Framework With Android and Java

rtker Block Diagram

Peripheral Devices & Protocols

Interfacing Serial/Parallel ports, USB, I2C, PCMIA, IDECommunication Serial, Ethernet, Low bandwidth radio, IrDA,

802.11b based devices.User Interface LCD, Keyboard, Touch sensors, Sound,

Digital pads, Webcams.Sensors A variety of sensors using fire, temperature,

pressure, water level, seismic, sound, vision.

Installation of ROSJAVA in Ubuntu Environment

Configure your ubuntu repositories

Configure your Ubuntu repositories to allow “restricted”, “universe”, “multiverse”.

Setup your sources.list

Setup your computer to accept software from ROS.org

Ubuntu 10.04(Lucid)

Page 18: Google's Rosjava Framework With Android and Java

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu lucid main" > /etc/apt/sources.list.d/ros-latest.list'

Ubuntu 11.10(Oneiric)

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu oneiric main" > /etc/apt/sources.list.d/ros-latest.list'

Set up your keys

wget http://packages.ros.org/ros.key -O - | sudo apt-key add -

Installation

Make sure you have re-indexed the ROS.org server:

sudo apt-get update

There are many different libraries and tools in ROS.  You can also install ROS stacks individually.

Desktop-Full Install: (Recommended): ROS, rx, rviz, robot-generic libraries, 2D/3D simulators, navigation and 2D/3D perception

sudo apt-get install ros-electric-desktop-full

Desktop Install: ROS, rx, rviz, and robot-generic libraries

sudo apt-get install ros-electric-desktop

ROS-Base: (Bare Bones): ROS package, build, and communication libraries. No GUI tools.

sudo apt-get install ros-electric-ros-base

Individual Stack: You can also install a specific ROS stack (replace underscores with dashes of the stack name):

sudo apt-get install ros-electric-STACK

Environment Setup

It's convenient if the ROS environment variables are automatically added to your bash session every time a new shell is launched:

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

If you have more than one ROS distribution installed, ~/.bashrc must only source the setup.bash for the version you are currently using.

Page 19: Google's Rosjava Framework With Android and Java

If you just want to change the environment of your current shell, you can type:

source /opt/ros/electric/setup.bash