Foxglove do not display 3D obstacle via SceneUpdate and SceneEnity

121 views Asked by At

I am using foxglove for 3D data visualization,if I only use PointCloud,it can display success as below:

enter image description here

However,I want to use it to display 3D Obstacle via SceneUpdate,but it not display the 3D data.

I have checked How to use Foxglove WebSocket server show a model?,but not helps. enter image description here

The full code is at foxglove-websocket-java(Github project),you can clone it and run FoxgloveApplication to start the application directly.

If anyone could help me,it would be very grateful and thanks in advance!

Related Code:

create topic

ChannelInfo channelScene = new ChannelInfo();
channelScene.setId(1);
channelScene.setTopic("SceneUpdate");
channelScene.setEncoding("json");
channelScene.setSchemaName("foxglove.SceneUpdate");
schema = DataUtil.loadJsonSchema("SceneUpdate.json");
channelScene.setSchema(schema);
channelScene.setSchemaEncoding("jsonschema");


ChannelInfo channelTransform = new ChannelInfo();
channelTransform.setId(2);
channelTransform.setTopic("frameTransform");
channelTransform.setEncoding("json");
channelTransform.setSchemaName("foxglove.FrameTransform");
schema = DataUtil.loadJsonSchema("FrameTransform.json");
channelTransform.setSchema(schema);
channelTransform.setSchemaEncoding("jsonschema");

create thread worker

public class SendTransformThread implements Runnable {

    private int frequency;
    private int index;
    private Session session;

    public SendTransformThread(int index, int frequency, Session session) {
        this.index = index;
        this.session = session;
        this.frequency = frequency;
    }

    @Override
    public void run() {
        int i = 0;
        while (true) {
            i = i > 10 ? 0 : i;
            i++;
            Timestamp timestamp = new Timestamp();
            int nano = Instant.now().getNano();
            long second = Instant.now().getEpochSecond();
            timestamp.setSec((int) second);
            timestamp.setNsec(nano);

            FrameTransform transform = new FrameTransform();
            transform.setTimestamp(timestamp);
            transform.setChild_frame_id("obstacle");
            transform.setParent_frame_id("root");

            Quaternion rotation = new Quaternion(1f + i, 2f + i, 1f + i, 1f + i / 3);
            transform.setRotation(rotation);

            Vector3 translation = new Vector3(1f, 2f + i, 1f + i);
            transform.setTranslation(translation);

            JSONObject jsonObject = (JSONObject) JSON.toJSON(transform);

            byte[] bytes = getFormatedBytes(jsonObject.toJSONString().getBytes(), nano, index);
            this.session.sendBinary(bytes);
            try {
                Thread.sleep(frequency);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

public class SendSceneUpdateThread implements Runnable {

    private int frequency;
    private int index;
    private Session session;

    public SendSceneUpdateThread(int index, int frequency, Session session) {
        this.index = index;
        this.session = session;
        this.frequency = frequency;
    }

    @Override
    public void run() {
        while (true) {

            SceneEntity entity = new SceneEntity();
            Timestamp timestamp = new Timestamp();
            int nano = Instant.now().getNano();
            long second = Instant.now().getEpochSecond();
            timestamp.setSec((int) second);
            timestamp.setNsec(nano);
            entity.setTimestamp(timestamp);
            entity.setFrame_id("obstacle");
            entity.setId(RandomStringUtils.randomAlphabetic(4).toLowerCase());
            entity.setFrame_locked(true);

            List<KeyValuePair> metadata = Arrays.asList(new KeyValuePair("category", "vehicle.truck"));
            entity.setMetadata(metadata);

            CubePrimitive cube = new CubePrimitive();
            Color color = new Color(1f, 0.38823529411764707f, 0.2784313725490196f, 0.5f);
            Vector3 size = new Vector3(10.201f, 2.877f, 3.595f);

            Pose pose = new Pose();
            Vector3 position = new Vector3(410.007f + 400, 1164.069f + 1000, 1.623f);
            Quaternion orientation = new Quaternion(0f, 0f, 0.812556848660791f, -0.5828819500503033f);
            pose.setPosition(position);
            pose.setOrientation(orientation);

            cube.setColor(color);
            cube.setSize(size);
            cube.setPose(pose);

            entity.setCubes(Arrays.asList(cube));

            SceneUpdate sceneUpdate = new SceneUpdate();
            sceneUpdate.setEntities(Arrays.asList(entity));
            JSONObject jsonObject = (JSONObject) JSON.toJSON(sceneUpdate);

            byte[] bytes = getFormatedBytes(jsonObject.toJSONString().getBytes(), nano, index);
            this.session.sendBinary(bytes);
            try {
                Thread.sleep(frequency);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

send data worker

Thread sendSceneUpdateThread = new Thread(new SendSceneUpdateThread(1, 1000, session));
sendSceneUpdateThread.start();

Thread sendTransformThread = new Thread(new SendTransformThread(0, 1000, session));
sendTransformThread.start();
0

There are 0 answers