@Override
 public boolean onTouchEvent(VisualizationView view, MotionEvent event) {
   if (visible) {
     Preconditions.checkNotNull(pose);
     if (event.getAction() == MotionEvent.ACTION_MOVE) {
       Vector3 orientationVector =
           camera
               .toWorldCoordinates(new Point((int) event.getX(), (int) event.getY()))
               .subtract(pose.getTranslation());
       if (orientationVector.length() > 0) {
         pose.setRotation(
             Quaternion.rotationBetweenVectors(new Vector3(1, 0, 0), orientationVector));
       } else {
         pose.setRotation(Quaternion.newIdentityQuaternion());
       }
       shape.setTransform(pose);
       requestRender();
       return true;
     } else if (event.getAction() == MotionEvent.ACTION_UP) {
       posePublisher.publish(
           pose.toPoseStampedMessage(
               camera.getFixedFrame(),
               connectedNode.getCurrentTime(),
               posePublisher.newMessage()));
       visible = false;
       requestRender();
       return true;
     }
   }
   gestureDetector.onTouchEvent(event);
   return false;
 }
예제 #2
0
 protected void publish() {
   if (publisher_string.isEmpty()) return;
   std_msgs.String string = publisher.newMessage();
   string.setData(publisher_string);
   publisher.publish(string);
   hasPublishedMsg = true;
   publisher_string = "";
 }
 public TurtlesimVelocityPublisherResource(ConnectedNode connectedNode)
     throws InterruptedException {
   System.out.println("\n\n---------> TurtlesimVelocityPublisherResource Constructor\n\n\n");
   velocity_publisher = connectedNode.newPublisher("/turtle1/cmd_vel", geometry_msgs.Twist._TYPE);
   System.out.printf("\n\n---------> velocity_publisher  %s\n\n\n", velocity_publisher);
   geometry_msgs.Twist cmd_vel = velocity_publisher.newMessage();
   System.out.printf("\n\n---------> cmd_vel %s\n\n\n", cmd_vel);
 }
 public void send_coordinate(float[] p_array) {
   string = publisher.newMessage();
   StringBuilder stringBuilder = new StringBuilder();
   stringBuilder.append("c_");
   stringBuilder.append(java.lang.String.valueOf(p_array[0]));
   stringBuilder.append('_');
   stringBuilder.append(java.lang.String.valueOf(p_array[1]));
   string.setData(stringBuilder.toString());
   publisher.publish(string);
 }
예제 #5
0
 private void publish(byte level, Object message) {
   rosgraph_msgs.Log logMessage = publisher.newMessage();
   logMessage.getHeader().setStamp(defaultNode.getCurrentTime());
   logMessage.setLevel(level);
   logMessage.setName(defaultNode.getName().toString());
   logMessage.setMsg(message.toString());
   // TODO(damonkohler): Should update the topics field with a list of all
   // published and subscribed topics for the node that created this logger.
   // This helps filter the rosoutconsole.
   publisher.publish(logMessage);
 }
  @GET // Handle HTTP Get requests
  @Path("{linear}") // URI components containing the parameter
  @Produces("text/plain")
  public String setLinearVelocity(@PathParam("linear") double linear) {
    System.out.printf("\n\n---------> velocity_publisher  %s\n\n\n", velocity_publisher);
    geometry_msgs.Twist cmd_vel = velocity_publisher.newMessage();
    System.out.printf("\n\n---------> cmd_vel %s\n\n\n", cmd_vel);
    cmd_vel.getLinear().setX(linear);

    velocity_publisher.publish(cmd_vel);

    return "done!";
  }
예제 #7
0
  @Override
  protected Bitmap processFrame(VideoCapture capture) {
    Time[] measureTime = new Time[9];
    String[] compDescStrings = {
      "Total processFrame",
      "Grab a new frame",
      "MatToBitmap",
      "Publish cameraInfo",
      "Create ImageMsg",
      "Compress image",
      "Transfer to Stream",
      "Image.SetData",
      "Publish Image",
      "Total econds per frame"
    };
    String[] rawDescStrings = {
      "Total processFrame",
      "Grab a new frame",
      "MatToBitmap",
      "Publish cameraInfo",
      "Create ImageMsg",
      "Pixel to buffer",
      "Transfer to Stream",
      "Image.SetData",
      "Publish Image",
      "Total seconds per frame"
    };

    measureTime[0] = connectedNode.getCurrentTime();

    switch (MainActivity.viewMode) {
      case MainActivity.VIEW_MODE_GRAY:
        //	            capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
        capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_GREY_FRAME);
        //	            Imgproc.cvtColor(mGray, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
        break;
      case MainActivity.VIEW_MODE_RGBA:
        capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
        //            Core.putText(mRgba, "OpenCV + Android", new Point(10, 100), 3, 2, new
        // Scalar(255, 0, 0, 255), 3);
        break;
      case MainActivity.VIEW_MODE_CANNY:
        capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
        Imgproc.Canny(mGray, mIntermediateMat, 80, 100);
        Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
        break;
    }
    Time currentTime = connectedNode.getCurrentTime();

    measureTime[1] = connectedNode.getCurrentTime();

    if (bmp == null) bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);

    if (MainActivity.imageCompression == MainActivity.IMAGE_TRANSPORT_COMPRESSION_NONE
        && bb == null) {
      Log.i(TAG, "Buffer 1");
      bb = ByteBuffer.allocate(bmp.getRowBytes() * bmp.getHeight());
      Log.i(TAG, "Buffer 2");
      bb.clear();
      Log.i(TAG, "Buffer 3");
    }
    try {
      Utils.matToBitmap(mRgba, bmp);
      measureTime[2] = connectedNode.getCurrentTime();

      cameraInfo = cameraInfoPublisher.newMessage();
      cameraInfo.getHeader().setFrameId("camera");
      cameraInfo.getHeader().setStamp(currentTime);
      cameraInfo.setWidth(640);
      cameraInfo.setHeight(480);
      cameraInfoPublisher.publish(cameraInfo);
      measureTime[3] = connectedNode.getCurrentTime();

      if (MainActivity.imageCompression >= MainActivity.IMAGE_TRANSPORT_COMPRESSION_PNG) {
        // Compressed image

        sensor_msgs.CompressedImage image = imagePublisher.newMessage();
        if (MainActivity.imageCompression == MainActivity.IMAGE_TRANSPORT_COMPRESSION_PNG)
          image.setFormat("png");
        else if (MainActivity.imageCompression == MainActivity.IMAGE_TRANSPORT_COMPRESSION_JPEG)
          image.setFormat("jpeg");
        image.getHeader().setStamp(currentTime);
        image.getHeader().setFrameId("camera");
        measureTime[4] = connectedNode.getCurrentTime();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (MainActivity.imageCompression == MainActivity.IMAGE_TRANSPORT_COMPRESSION_PNG)
          bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
        else if (MainActivity.imageCompression == MainActivity.IMAGE_TRANSPORT_COMPRESSION_JPEG)
          bmp.compress(Bitmap.CompressFormat.JPEG, MainActivity.imageCompressionQuality, baos);
        measureTime[5] = connectedNode.getCurrentTime();

        stream.buffer().writeBytes(baos.toByteArray());
        measureTime[6] = connectedNode.getCurrentTime();

        image.setData(stream.buffer().copy());
        measureTime[7] = connectedNode.getCurrentTime();

        stream.buffer().clear();
        imagePublisher.publish(image);
        measureTime[8] = connectedNode.getCurrentTime();
      } else {
        // Raw image

        Log.i(TAG, "Raw image 1");
        sensor_msgs.Image rawImage = rawImagePublisher.newMessage();
        rawImage.getHeader().setStamp(currentTime);
        rawImage.getHeader().setFrameId("camera");
        rawImage.setEncoding("rgba8");
        rawImage.setWidth(bmp.getWidth());
        rawImage.setHeight(bmp.getHeight());
        rawImage.setStep(640);
        measureTime[4] = connectedNode.getCurrentTime();

        Log.i(TAG, "Raw image 2");

        bmp.copyPixelsToBuffer(bb);
        measureTime[5] = connectedNode.getCurrentTime();

        Log.i(TAG, "Raw image 3");

        stream.buffer().writeBytes(bb.array());
        bb.clear();
        measureTime[6] = connectedNode.getCurrentTime();

        Log.i(TAG, "Raw image 4");

        rawImage.setData(stream.buffer().copy());
        stream.buffer().clear();
        measureTime[7] = connectedNode.getCurrentTime();

        Log.i(TAG, "Raw image 5");

        rawImagePublisher.publish(rawImage);
        measureTime[8] = connectedNode.getCurrentTime();
        Log.i(TAG, "Raw image 6");
      }

      newTime = connectedNode.getCurrentTime();
      stats[9][counter] = (newTime.subtract(oldTime)).nsecs / 1000000.0;
      oldTime = newTime;

      for (int i = 1; i < 9; i++) {
        stats[i][counter] = (measureTime[i].subtract(measureTime[i - 1])).nsecs / 1000000.0;
      }

      stats[0][counter] = measureTime[8].subtract(measureTime[0]).nsecs / 1000000.0;

      counter++;
      if (counter == numSamples) {
        double[] sts = new double[10];
        Arrays.fill(sts, 0.0);

        for (int i = 0; i < 10; i++) {
          for (int j = 0; j < numSamples; j++) sts[i] += stats[i][j];

          sts[i] /= (double) numSamples;

          if (MainActivity.imageCompression >= MainActivity.IMAGE_TRANSPORT_COMPRESSION_PNG)
            Log.i(TAG, String.format("Mean time for %s:\t\t%4.2fms", compDescStrings[i], sts[i]));
          else Log.i(TAG, String.format("Mean time for %s:\t\t%4.2fms", rawDescStrings[i], sts[i]));
        }
        Log.i(TAG, "\n\n");
        counter = 0;
      }

      return bmp;
    } catch (Exception e) {
      Log.e(TAG, "Frame conversion and publishing throws an exception: " + e.getMessage());
      bmp.recycle();
      return null;
    }
  }
예제 #8
0
  @Override
  public void onStart(final ConnectedNode connectedNode) {
    this.connectedNode = connectedNode;
    try {
      serviceClient =
          connectedNode.newServiceClient(
              "bb_estimator/estimate_bb", srs_env_model_percp.EstimateBB._TYPE);
    } catch (ServiceNotFoundException e) {
      throw new RosRuntimeException(e);
    }

    final Publisher<geometry_msgs.Twist> publisherRotate =
        connectedNode.newPublisher(MoveTopic.trim(), geometry_msgs.Twist._TYPE);
    final Publisher<geometry_msgs.PoseStamped> publisherMove =
        connectedNode.newPublisher(GoalTopic.trim(), geometry_msgs.PoseStamped._TYPE);
    final geometry_msgs.Twist rotace = publisherRotate.newMessage();
    final geometry_msgs.PoseStamped cil = publisherMove.newMessage();
    // This CancellableLoop will be canceled automatically when the node shuts down.
    connectedNode.executeCancellableLoop(
        new CancellableLoop() {
          private boolean leftE, rightE, goE, backE, moveE;
          private int seq;

          @Override
          protected void setup() {
            leftE = false;
            rightE = false;
            goE = false;
            backE = false;
            moveE = false;
            seq = 0;
          }

          @Override
          protected void loop() throws InterruptedException {
            /* ROTACE  */
            leftE = left;
            rightE = right;
            goE = go;
            backE = back;
            moveE = move;
            rotace.getAngular().setZ(0);
            rotace.getLinear().setX(0);
            if (leftE) {
              leftE = false;
              left = false;
              rotace.getAngular().setZ(-2);
              for (int i = 0; i < 6; i++) {
                publisherRotate.publish(rotace);
                Thread.sleep(300);
              }
            } else if (rightE) {
              rightE = false;
              right = false;
              rotace.getAngular().setZ(2);
              for (int i = 0; i < 6; i++) {
                publisherRotate.publish(rotace);
                Thread.sleep(300);
              }
            } else if (goE) {
              goE = false;
              go = false;
              rotace.getLinear().setX(1.3);
              publisherRotate.publish(rotace);
            } else if (backE) {
              backE = false;
              back = false;
              rotace.getLinear().setX(-1.3);
              publisherRotate.publish(rotace);
            }

            /* Pohyb k cily */
            if (moveE) {
              moveE = false;
              move = false;
              seq++;
              cil.getHeader().setFrameId("/map");
              cil.getHeader().setSeq(seq);
              cil.getPose().getPosition().setX(x);
              cil.getPose().getPosition().setY(y);
              System.out.println("PublisherMove: X:" + x + ",Y:" + y);
              cil.getPose().getOrientation().setX(0);
              cil.getPose().getOrientation().setY(0);
              cil.getPose().getOrientation().setZ(0);
              cil.getPose().getOrientation().setW(1);
              publisherMove.publish(cil);
              // Toast.makeText(ctxt, "Robot is moving to goal", Toast.LENGTH_LONG).show();
            }

            Thread.sleep(300);
          }
        });
  }
 public void sendMessage(java.lang.String p_string) {
   string = publisher.newMessage();
   string.setData(p_string);
   publisher.publish(string);
 }
예제 #10
0
 public void sendCloseMenu() {
   string = publisher.newMessage();
   string.setData("menu_close");
   publisher.publish(string);
 }