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


android_apps
Author(s): Daniel Stonier , Kazuto Murase
autogenerated on Thu Jun 6 2019 21:11:28