Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

350 mission backend #369

Merged
merged 6 commits into from
Apr 23, 2018
Merged

350 mission backend #369

merged 6 commits into from
Apr 23, 2018

Conversation

JonasVautherin
Copy link
Collaborator

Add UploadMission and StartMission to the mission backend.

Connects to #350.

{
// TODO
auto upload_handle = uploadMissionAndSaveParams(nullptr, nullptr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
// TODO
auto upload_handle = uploadMissionAndSaveParams(nullptr, nullptr);
_result_callback(dc::Mission::Result::UNKNOWN);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would the result be UNKNOWN? I think the result should only be unknown if something in the enum translation went wrong. If it is an actual error, it should be ERROR or some specific error code, right?

Or is it that the error is unknown because with nullptr the callback has not actually been called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just that I need to synchronize the call in the service (see here and here). So the upload call is blocked until the callback is actually called (this assumes that the callback is always called, eventually).

The value of it in this unit test has not importance. It just needs to trigger. Maybe I should make it a variable called ARBITRARY_RESULT, to make this clear!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question is also whether it would make sense to make a sync upload_mission(...) function in the core libs as well, so that I could get rid of this future here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yer UNKNOWN is totally fine then.

One question is also whether it would make sense to make a sync upload_mission(...) function in the core libs as well, so that I could get rid of this future here.

So, is the easier way to use sync calls in the grpc backend? If yes, then it probably makes sense to have sync calls by default.

auto request = generateUploadRequest(mission_items);
auto upload_handle = uploadMissionAndSaveParams(request, response);

_result_callback(GetParam().second);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help me please. What's GetParam() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's about the parameterized tests. You see it is parameterized because it is a TEST_P. And the parameters are instantiated here. So GetParam().second will get the second value of each of the pairs initialized here (i.e. the test is run once for each pair).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, got it, thank you!

auto mission_item = std::make_shared<dc::MissionItem>();
mission_item->set_position(41.848695, 75.132751);
mission_item->set_relative_altitude(50.4);
mission_item->set_speed(8.3);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the fields are actually floats and so it should be 8.3f, however, I wonder if we shouldn't just make everything double in DroneCore, especially in the public interface since DroneCore is not run on embedded platforms generally and everything is becoming 64 bits these days.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, is the compiler here generating a double with value 8.3, and then implicitly casting it to a float? I will fix that.

I am not familiar with performance issues on embedded platforms, so I'll follow you on that (but dronecore could be run onboard the drone, right?). For me it's not a big problem to have floats. We will just need to stick to our decisions as it will be define in the proto files :-).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the onboard computers are likely arm64 these days, so moving to a double only interface might make sense.

bool operator==(const MissionItem &lhs, const MissionItem &rhs)
{
return (lhs.get_latitude_deg() == rhs.get_latitude_deg()
|| isnan(lhs.get_latitude_deg()) && isnan(rhs.get_latitude_deg()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to make it explicit what the operator order is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. macOS is warning about that, and apparently I did not fix it on the right computer. I'll change it!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, it's a warning. The operator precedence is clear in theory but it's nice for the reader to make it explicit in my opinion.

<< "\tloiter_time: " << mission_item.get_loiter_time_s() << std::endl
<< "\tcamera_action: " << mission_item.get_camera_action() << std::endl
<< "\tcamera_photo_interval: " << mission_item.get_camera_photo_interval_s()
<< std::endl << "]" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

case MissionItem::CameraAction::STOP_VIDEO:
return str << "CameraAction::STOP_VIDEO";
case MissionItem::CameraAction::NONE:
return str << "CameraAction::NONE";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do the same kind of thing instead of the result_str() methods.

@@ -8,13 +8,14 @@
namespace dronecore {
namespace testing {

typedef std::function<void(Mission::Result)> result_callback_t;
typedef std::function<void(Mission::Result)> mission_result_callback_t;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you get this typedef from somwhere else? Or is it specific to testing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I did not want to take Mission::result_callback_t, but for wrong reasons :-).

Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge whenever you're done with the changes.

Effectively fixing the type of the relative altitude field in MissionItem
(was double, needs float).
* Add an ARBITRARY_RESULT to tests to make it clear that the result does not matter
* Make comparison operators priority clear by adding parentheses
* Use result_callback_t from Mission instead or redefining it
* Fix some floats assignments ("f" suffix was forgotten)
@JonasVautherin JonasVautherin merged commit c84df75 into develop Apr 23, 2018
@JonasVautherin JonasVautherin deleted the 350-mission-backend branch April 23, 2018 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants