Exemplo n.º 1
0
 @Override
 public void onStart(ConnectedNode connectedNode) {
   // Subscribe to the laser scans.
   Subscriber<sensor_msgs.LaserScan> laserScanSubscriber =
       connectedNode.newSubscriber(laserTopic, sensor_msgs.LaserScan._TYPE);
   laserScanSubscriber.addMessageListener(this);
   // Subscribe to the command velocity. This is needed for auto adjusting the
   // zoom in ZoomMode.VELOCITY_ZOOM_MODE mode.
   Subscriber<geometry_msgs.Twist> twistSubscriber =
       connectedNode.newSubscriber("cmd_vel", geometry_msgs.Twist._TYPE);
   twistSubscriber.addMessageListener(
       new MessageListener<geometry_msgs.Twist>() {
         @Override
         public void onNewMessage(final geometry_msgs.Twist robotVelocity) {
           post(
               new Runnable() {
                 @Override
                 public void run() {
                   distanceRenderer.currentSpeed(robotVelocity.getLinear().getX());
                 }
               });
         }
       });
   setOnTouchListener(this);
   // Load the last saved setting.
   distanceRenderer.loadPreferences(this.getContext());
 }
Exemplo n.º 2
0
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   final int action = event.getAction();
   switch (action & MotionEvent.ACTION_MASK) {
     case MotionEvent.ACTION_MOVE:
       {
         // Only zoom when there are exactly 2 contacts on the view.
         if (event.getPointerCount() == 2) {
           // Get the current distance between the 2 contacts.
           double currentContactDistance =
               calculateDistance(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
           // Calculate the delta between the current contact location and the
           // previous contact locations. Then add (a fraction of) that delta to
           // the existing normalized value for zoom.
           // Using half the width of the view provides an appropriate level of
           // sensitivity while zooming.
           normalizedZoomValue +=
               (currentContactDistance - contactDistance) / (this.getWidth() / 2);
           if (normalizedZoomValue > 1) {
             normalizedZoomValue = 1;
           } else if (normalizedZoomValue < 0) {
             normalizedZoomValue = 0;
           }
           distanceRenderer.setNormalizedZoom((float) normalizedZoomValue);
           // Remember the current distance between coordinates for later.
           contactDistance = currentContactDistance;
         }
         break;
       }
       // When the second contact touches the screen initialize contactDistance
       // for the immediate round of interaction.
     case MotionEvent.ACTION_POINTER_1_DOWN:
       {
         contactDistance =
             calculateDistance(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
         break;
       }
   }
   return true;
 }
Exemplo n.º 3
0
 /**
  * Updates the current speed in {@link #distanceRenderer} which then can adjust the zoom level in
  * velocity mode.
  *
  * @param speed The linear velocity of the robot.
  */
 public void currentSpeed(double speed) {
   distanceRenderer.currentSpeed(speed);
 }
Exemplo n.º 4
0
 /** Unlocks the zoom allowing it to be changed. */
 public void unlockZoom() {
   distanceRenderer.unlockZoom();
 }
Exemplo n.º 5
0
 /** Prevents changes to the zoom level. */
 public void lockZoom() {
   distanceRenderer.lockZoom();
 }
Exemplo n.º 6
0
 /**
  * Sets the zoom mode to one of the modes in {@link ZoomMode}.
  *
  * @param mode The zoom mode that must be set.
  */
 public void setZoomMode(ZoomMode mode) {
   distanceRenderer.setZoomMode(mode);
 }
Exemplo n.º 7
0
 @Override
 public void onShutdownComplete(Node node) {
   // Save the existing settings before exiting.
   distanceRenderer.savePreferences(this.getContext());
 }