tuofeichen / MAV-Project

1 stars 0 forks source link

Frontend code structure #1

Closed tuofeichen closed 8 years ago

tuofeichen commented 8 years ago

Alright, here's the deal.

In the main.cpp code, I added some read out to get the current position estimate by visual SLAM: https://github.com/jameswhang/MAV-Project/blob/master/px4_ws/src/rgbd_slam/src/main.cpp#L240:L245

While the code seems to be doing a pretty good job estimating the position, I don't get where the currentPosition get updated in the backend class. The only place it seems to get updated is here:

https://github.com/jameswhang/MAV-Project/blob/master/px4_ws/src/rgbd_slam/src/Backend.cpp#L77

but I don't see the deserializeCurrentNode get called anywhere in Frontend.

I suspect there's some interesting message passing via TCP, since this position estimate is definitely done in backend (to not confuse things, I mean the physical backend, the laptop), because the frontend only estimates the transformation which is the change of the position, while the backend did the integration and pose graph optimization.

So I think the backend is spitting out position estimate constantly, and I think the frontend get the message just fine in TCP, but without deserializeCurrentNode I don't know how that's used to update the currentPosition in backend class.

Also, the backend thread might be doing something just on its own, Idk.

Any ideas?

jameswhang commented 8 years ago

Take this one by one: Backend.cpp updates the current position in the call to deserializeCurrentNode, which is wrapped by the wrapper function deserializeCurrentNodeWrapper.

Now take a look at line 23 in Backend.cpp:

protocolHandler.registerRecvCallback(UavComProtocol::CMD1::CURRENT_NODE,deserializeCurrentNodeWrapper,this);

Basically, every time backend receives a packet via TCP, it calls deserializeCurrentNodeWrapper as its 'callback' action. This callback function is basically something that gets called whenever an event happens. It's called event-driven programming - google it to find out more.

Anyways, deserializeCurrentNodeWrapper will then call deserializeCurrentNode, and this will update the current position in the backend.

Let me know if this doesn't make sense.