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

Add dynamic avoidance reaction #104

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Samir-Rashid
Copy link
Contributor

@Samir-Rashid Samir-Rashid commented Jan 31, 2024

Greetings, gamers.
This PR desperately needs some CPR. I am requesting some backup in reviving this. As it is right now, it is just skeleton code. I think the comments express the idea I was going for. (TLDR: camera is always taking pics in another thread and this should trigger a state transition iff in airdrop state to emergency avoidance state which changes altitude until it cannot see an obstacle)

There are a few issues:

  • 1. This PR depends on @hashreds PR to get finished so that I can do inference with SAM
  • 2. This PR depends on the camera code that @dzodkin33 wrote. There is going to be a refactor at some point, but that is not currently scheduled.
  • 3. Also we don't even know what camera is going to be used yet! Is there even a spot on the plane? That camera needs to get code added to take photos.
  • 4. I do not know how to test the custom mavlink command code I wrote. There is a special message to change altitude and continue along a waypoint path which I want to use. This is not in mavsdk, so I had to use the passthrough.
  • 5. we need to compile mavlink to use plugins (Passthrough is a plugin)
  • 6. I have to update to the newest Tick architecture (should not be hard)

@Samir-Rashid Samir-Rashid linked an issue Jan 31, 2024 that may be closed by this pull request
3 tasks
@Samir-Rashid Samir-Rashid force-pushed the feat/dynamic-avoidance-behavior branch from 069cb63 to e9b16ba Compare February 5, 2024 00:37
};


// Wait until health is OK and vehicle is ready to arm
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignore this

@Samir-Rashid Samir-Rashid marked this pull request as ready for review April 5, 2024 04:09
public:
// Do not use a default constructor. The evasion state needs to know
// the location of the obstacle
ObstacleEvasionState() = delete;
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if you need to delete the default constructor. I think if you define another one it will not generate a default one. But deleting it shouldn't hurt.

// Output after an obstacle has been detected
struct Detection {
std::chrono::time_point<std::chrono::system_clock> time;
// TODO(Samir): is there a type for location of bounding box
Copy link
Member

Choose a reason for hiding this comment

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

There is a bounding box but it stores two corners of the bounding box, not the center of the bounding box.

class Bbox {
public:
int x1;
int y1;
int x2;
int y2;
int width();
int height();
};

Comment on lines +44 to +65
class ObstacleDetectionQueue {
public:
ObstacleDetectionQueue();
void add(Detection detection);
bool isEmpty();
// prune every image older than `age` seconds ago
void pruneQueue(int age);
// copies the queue so you can look at the data
void copyQueue(std::queue<Detection> queue);

private:
// This is used to store all previous obstacles.
// We need to make sure that a detection is not spurious
// before engaging in emergency evasion.
std::queue<Detection> queue;
// Note that Step 4 in "Steps" above only triggers on a boolean
// condition. I am still making this Detection queue thread safe
// because it can be useful to be able to access this in the main
// program. For example, once emergency evasion is engaged it can
// poll the queue to make sure there is nothing more to evade.
std::mutex mutex;
};
Copy link
Member

Choose a reason for hiding this comment

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

I like hiding the complexity of the queue a lot and exposing a thread safe interface. It would be nice if we could have a generic version of this for all of obcpp since so many places are using thread safe queues.

Comment on lines +58 to +62
ObstacleDetectionQueue::pruneQueue();

// TODO: check if the boxes are getting larger AND bigger than a threshold
std::queue<Detection> queue;
ObstacleDetectionQueue::copyQueue(queue);
Copy link
Member

Choose a reason for hiding this comment

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

What does the :: syntax here do? I might be trolling with C++ but I thought you needed to create an ObstacleDetectionQueue instance to call methods on it?

Comment on lines +70 to +74
// TODO: I am rethinking this now and it does not make sense to
// have dynamic obstacle detection be part of it's own state.
// The dynamic detection should be a part of a separate thread and
// send a message to the Airdrop state to switch to the dynamic avoidance
// state.
Copy link
Member

Choose a reason for hiding this comment

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

I agree with this sentiment. I think it should be running in another thread during Airdrop and Search states.

@Samir-Rashid
Copy link
Contributor Author

I will close this PR unless anyone objects. Ultimately, I do not believe vision is a satisfactory approach for dynamic avoidance. It would not be the worst to adapt the ideas from this PR to next year. However, we need to have a proper LiDAR solution at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add evasion state and behavior
3 participants