GithubHelp home page GithubHelp logo

0000duck / ros-qml-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from severin-lemaignan/ros-qml-plugin

0.0 1.0 0.0 39 KB

A QML plugin to interact with ROS from QtQuick applications

QMake 2.71% C++ 97.29%

ros-qml-plugin's Introduction

ROS QML plugin

Supports:

When used in conjunction with QML Box2D plugin, it can also publish the (Box2D) bounding boxes of items as polygons.

Requirements

  • qt5. On Debian/Ubuntu: apt install qmake qt5-default qtdeclarative5-dev
  • ROS (tested with ROS kinectic, but should work with other versions as well)

Installation

The following commands compile and install the QML plugin in the QML dir, making it available to any QML application.

> mkdir build
> cd build
> qmake ..
> make
> make install

Known Issue

ROS has a known error in its pkgconfig files (.pc) as libs dependencies are specified as -l:/path/libname.so: -l: should be removed. This can be done by updating the .pc files in ROS:

> cd /opt/ros/kinetic/lib/pkgconfig/
> sudo sed -i "s/-l://g" *

General Usage

Call ros::init in your main.cpp:

//...
#include <ros/ros.h>

int main(int argc, char *argv[])
{
    ros::init(argc, argv,"your_node_name");

    QGuiApplication app(argc, argv);

    //...
}

Then, in your QML files:

import Ros 1.0

Item {
  id: test

  //...

 TFBroadcaster {
    target: test
    frame: "test_frame"
 }

 Image {
    //...

    ImagePublisher {
      id: imgPublisher
      target: parent
      topic: "/qmlapp/image"
      frame: "/map"
      width: 800
      height: 600
    }

    onPaintedGeometryChanged: imgPublisher.publish()

 }

 //... see below for the list of supported functionalities

}

ImagePublisher

You can publish the content of any QML image as a ROS image using the ImagePublisher object.

The ImagePublisher class provides a QML object that publishes a QImage on a ROS topic (set it with the 'topic' property). The QML property 'target' must refer to a QML image. The property 'frame' should be set to the desired ROS frame.

The image is published everytime the method 'publish()' is called.

The size of the image can be set with the property 'width' and 'height'. By default, the actual size of the image item is used.

The image can be published on a latched topic by setting latched: True (by default, not latched).

The property 'pixelscale' is used to compute the (virtual) focal length: f = 1/pixelscale. This can be used to convert the image's pixels into meters in the ROS code: 1 meter = 1 pixel * 1/f

Example:

Image {
    //...

    ImagePublisher {
      id: imgPublisher
      target: parent // object to publish
      topic: "/qmlapp/image" // the desired ROS image topic
      frame: "/map" // reference frame for that image
      width: 800
      height: 600
      latched: false // if you want a latched topic (default: false)
      pixelscale: 1 // inverse of the (virtual) focal length (cf explanation above)
    }

    onPaintedGeometryChanged: imgPublisher.publish() // call publish() everytime the image data changes

}

Displaying ROS image topics

This uses a special QML ImageProvider to read images from a ROS topic. Specify the topic using: img.source = "image://rosimage/<your topic>".

Typical usage, that refreshes the image at 20Hz:

import Ros 1.0

Image {
	id: img
	cache: false

	anchors.fill: parent
	source: "image://rosimage/v4l/camera/image_raw"

	Timer {
		interval: 50
		repeat: true
		running: true
		onTriggered: { img.source = ""; img.source = "image://rosimage/v4l/camera/image_raw" }
	}
}

TFBroadcaster

Publishes the position (x,y,theta) of a QML item as a TF frame. Pixel to meters conversion is controlled by the pixelscale parameter.

Item {
  id: test

 TFBroadcaster {
    target: parent // reference to the item whose position is broadcasted
    frame: "test_frame" // name of the TF frame. Mandatory.
    parentframe: "parent_frame" // name of the parent frame. Mandatory.
    pixelscale: 2 // meters = pixel * pixelscale, by default 1
    origin: originItem // reference to a QML item acting as reference point. By default, scene's (0,0)
    zoffset: 1 // if set, used as the `z` coordinate of the TF frame. By default, 0
 }
}

TFListener

RosPose

RosPose is a QML item whose position can be updated from a ROS Pose message.

Only the pose.x and pose.y are used. Use pixelscale to set the conversion factor between pixels and meters (see example below).

The (x, y) coordinates are relative to the QML item origin.

The following example uses poses published on the /poses topic to move a blue rectangle on the screen:

Window {

    RosPose {
        id: mypose
        topic: "/poses"
        origin: parent
        pixelscale: 200 // 200 pixels = 1 meter

        Rect {
            width: 10
            height: 10
            color: "blue"
        }
    }
}

You can as well use onPositionChanged to react to position changes.

ros-qml-plugin's People

Contributors

emmanuel-senft avatar severin-lemaignan avatar skadge avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.