InitialPoseSubscriberLayer.java
Go to the documentation of this file.
00001 package com.github.rosjava.android_apps.map_nav;
00002 
00003 import javax.microedition.khronos.opengles.GL10;
00004 
00005 import org.ros.android.view.visualization.Camera;
00006 import org.ros.android.view.visualization.layer.SubscriberLayer;
00007 import org.ros.android.view.visualization.layer.TfLayer;
00008 import org.ros.android.view.visualization.shape.RobotShape;
00009 import org.ros.android.view.visualization.shape.Shape;
00010 import org.ros.message.MessageListener;
00011 import org.ros.namespace.GraphName;
00012 import org.ros.node.ConnectedNode;
00013 import org.ros.rosjava_geometry.FrameName;
00014 import org.ros.rosjava_geometry.FrameTransform;
00015 import org.ros.rosjava_geometry.FrameTransformTree;
00016 import org.ros.rosjava_geometry.Transform;
00017 
00018 import android.os.Handler;
00019 
00020 public class InitialPoseSubscriberLayer extends
00021                 SubscriberLayer<geometry_msgs.PoseStamped> implements TfLayer {
00022 
00023         private static final String ROBOT_FRAME = "base_link";
00024         private final FrameName targetFrame;
00025 
00026         private Shape shape;
00027 
00028         public InitialPoseSubscriberLayer(String topic) {
00029                 this(GraphName.of(topic));
00030         }
00031 
00032         public InitialPoseSubscriberLayer(GraphName topic) {
00033                 super(topic, "geometry_msgs/PoseStamped");
00034                 targetFrame = FrameName.of(ROBOT_FRAME);
00035         }
00036 
00037         @Override
00038         public void draw(GL10 gl) {
00039                         shape.draw(gl);
00040         }
00041 
00042         @Override
00043         public void onStart(ConnectedNode connectedNode, Handler handler,
00044                         final FrameTransformTree frameTransformTree, Camera camera) {
00045                 super.onStart(connectedNode, handler, frameTransformTree, camera);
00046             shape = new RobotShape();
00047                 getSubscriber().addMessageListener(
00048                                 new MessageListener<geometry_msgs.PoseStamped>() {
00049                                         @Override
00050                                         public void onNewMessage(geometry_msgs.PoseStamped pose) {
00051                                                 FrameName source = FrameName.of(pose.getHeader()
00052                                                                 .getFrameId());
00053                                                 FrameTransform frameTransform = frameTransformTree
00054                                                                 .transform(source, targetFrame);
00055                                                 if (frameTransform != null) {
00056                                                         Transform poseTransform = Transform
00057                                                                         .fromPoseMessage(pose.getPose());
00058                                                         shape.setTransform(frameTransform.getTransform()
00059                                                                         .multiply(poseTransform));
00060                                                 }
00061                                         }
00062                                 });
00063         }
00064 
00065         @Override
00066         public FrameName getFrame() {
00067                 return targetFrame;
00068         }
00069 }


android_apps
Author(s): Daniel Stonier , Kazuto Murase
autogenerated on Fri Aug 28 2015 10:04:40