[Sensor] Decouple sensor initialization from Agent#1064
[Sensor] Decouple sensor initialization from Agent#1064vauduong merged 36 commits intofacebookresearch:masterfrom
Conversation
…sensors in Simulator::addAgent()
… decouple-sensors formatting
| scene::SceneNode& node, | ||
| const sensor::SensorSetup& sensorSetup) { | ||
| sensor::SensorSuite sensorSuite = sensor::SensorSuite(); | ||
| for (sensor::SensorSpec::ptr spec : sensorSetup) { |
There was a problem hiding this comment.
This is already decoupled on the Python side FYI. It's even factored out on the Python side to a sensor can be added without reconfiguring the sim. Seems like this should be refactored to also have a function to add a single sensor like we have on the Python side agent.add_sensor()...
There was a problem hiding this comment.
Hi @Skylion007
If possible, I sincerely hope you can help us to take a look at the internal task (I will send you the task number via slack), where we gave concrete implementation steps. Check if something is contradictory to what has been done in the Python side. Thanks!
jturner65
left a comment
There was a problem hiding this comment.
Please remember to document your added functions.
| .def_property_readonly( | ||
| "gfx_replay_manager", &Simulator::getGfxReplayManager, | ||
| R"(Use gfx_replay_manager for replay recording and playback.)") | ||
| .def_property_read_only("sensor_suite", &Simulator::getSensorSuite) |
There was a problem hiding this comment.
This is going to conflict with the Simulator python class. Furthermore, the Python sensorsuite is entirely seperate from the C++ one, we need to do more work before merging them.
There was a problem hiding this comment.
Thanks for the feedback Aaron, I see now that the python sensor suite is a Dict[str, hsim.Sensor], while the C++ SensorSuite is std::map<std::string, Sensor::ptr>. In this PR, we are making changes that we'd like to see on the C++ side, but I don't know enough about the python side to know if we'd like to see the same changes. It seems like the functionality to just add sensors already exists, right? Do you think I should modify how python sensors work to add them using this SensorFactory method, or just leave it as is?
There was a problem hiding this comment.
Oh I think I understand now, we should implement a similar SensorFactory method on the python side to create sensors.
| .def("get", &SensorSuite::get, R"(get the sensor by id)"); | ||
|
|
||
| // ==== SensorFactory ==== | ||
| py::class_<SensorFactory>(m, "SensorFactory") |
There was a problem hiding this comment.
This should be a factory method on the Sensorsuite, there is no reason for this particular class to be bound in Python like so. You should add python tests to see the divergent behavior.
|
@Skylion007 : when you have time, can you take a look at the slack channel? Thanks! |
| * @param resolution vec2i of resolution to set spec to | ||
| * | ||
| */ | ||
| void addSensorToObject(const int objectId, |
There was a problem hiding this comment.
When designing this API, please take a look at the definitions of the other similar "add" functions, such as addAgent.
The return can be a pointer to that new sensor. So you can memorize this sensor in your demo. You do not need that global sensorSuite_ in the simulator.
The input should be object Id or a scene::SceneNode of that object (You can create an overload function, and use one to call the other.) + a sensorSpec (instead of the pos + orientation + resolution).
|
|
||
| std::vector<agent::Agent::ptr> agents_; | ||
| // SensorSuite of all sensors available to the simulator | ||
| esp::sensor::SensorSuite sensorSuite_; |
There was a problem hiding this comment.
I do not think you need this sensorSuite_. Maybe you can have one defined in the viewer.cpp for your demo, but not in the simulator.
@aclegg3 : How do you think? I remembered that when we discuss this project, you mentioned once that we might need such a global sensorSuite to collect all the sensors? Can you think of any usage case where such a global sensorSuite is a must-have?
There was a problem hiding this comment.
Python uses its own for backwards compatability, but there is no reason if you can quickly and easily get all the sensors in the scene.
There was a problem hiding this comment.
Thanks for the comments - I included a global sensorSuite_ into Simulator to keep track of all the sensors. I thought about just keeping a pointers to the last added sensor, but later reasoned that it would be useful to be able to get all the sensors, not just the agent sensor and the last added sensor.
I'm happy to change this, but right now it seems like it's not so easy to get all the sensors in the scene.
Let me know any thoughts or if there is a better way to keep track of all the sensors! :)
There was a problem hiding this comment.
The question is that why you need to get all the sensors in the scene?
When you add a sensor to an object, the "add" function should give a pointer to this sensor, and you keep it somewhere so that you can use it later.
I am not against to have such a sensorSuite in the viewer.cpp for example, but not here, in the simulator class.
|
|
||
| const int defaultAgentId_ = 0; | ||
| esp::agent::Agent::ptr defaultAgent_ = nullptr; | ||
| std::string lastAddedObjectName_ = ""; |
There was a problem hiding this comment.
All the new code in the viewer.cpp is for your demo only. Perhaps you do not have to commit it in with this PR.
So this PR should include probably everything expect the viewer.cpp.
Then you create a new branch on top of this branch, vauduong:decouple-sensors (careful, not on top of the master) and put the modified viewer.cpp in that new branch (no PR is needed.)
|
EDIT: Can hold off on review, going to make some changes - getting rid of global SensorSuite @aclegg3 @eundersander @jturner65 @Skylion007 @mosra @erikwijmans |
bigbike
left a comment
There was a problem hiding this comment.
The PR is improved a lot. We are almost there. :)
|
@aclegg3 @eundersander @jturner65 @Skylion007 @mosra @erikwijmans @bigbike |
…1064) - Create a factory class SensorFactory, which contains a static method to return a SensorSuite given a reference to a - - SceneNode and reference to a vector of SensorSpec::ptrs called SensorSetup. - Add method SensorSuite::merge to merge the sensors from another SensorSuite into its existing map of sensors - SensorFactory is called in Simulator::AddAgent to provide sensors. - Add method Simulator::addSensorToObject to add a sensor at a node, given the node's objectId and the specification of the sensor - Add tests in SimTest and SensorTest
…1064) - Create a factory class SensorFactory, which contains a static method to return a SensorSuite given a reference to a - - SceneNode and reference to a vector of SensorSpec::ptrs called SensorSetup. - Add method SensorSuite::merge to merge the sensors from another SensorSuite into its existing map of sensors - SensorFactory is called in Simulator::AddAgent to provide sensors. - Add method Simulator::addSensorToObject to add a sensor at a node, given the node's objectId and the specification of the sensor - Add tests in SimTest and SensorTest
…1064) - Create a factory class SensorFactory, which contains a static method to return a SensorSuite given a reference to a - - SceneNode and reference to a vector of SensorSpec::ptrs called SensorSetup. - Add method SensorSuite::merge to merge the sensors from another SensorSuite into its existing map of sensors - SensorFactory is called in Simulator::AddAgent to provide sensors. - Add method Simulator::addSensorToObject to add a sensor at a node, given the node's objectId and the specification of the sensor - Add tests in SimTest and SensorTest
|
|
||
| #include "esp/scene/SceneNode.h" | ||
| #include "esp/sensor/CameraSensor.h" | ||
| #include "esp/sensor/Sensor.h" |
Motivation and Context
Currently, agents are constructed using a valid scene node reference and an agent configuration in the c++ habitat-sim function Simulator::addAgent. The agent configuration specifies sensor specifications, and the sensors are initialized in the agent constructor using the provided scene node.
This PR just focuses on the C++ side, but another PR can be made in the future to bring the functionality to python.
Sensors can be constructed using any valid scene node, so we wish to decouple sensor initialization from the agent. In this PR, we:
To demo this functionality, methods were added to Simulator to keep track of Sensors and get Sensors by object ID; and methods were added to Viewer to add CameraSensors to objects and toggle between agent and object cameras. You can see a video of a banana being pushed here:
BananaDemo.mov
How Has This Been Tested
Build and run with demo in viewer
Add test to add object in SimTest
Add test to test SensorFactory in SensorTest
Types of changes
Checklist