Skip to content

Commit

Permalink
[OP-160] Urban Driving - Send Mode to AlertManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Aguilar committed Sep 23, 2020
1 parent 43e94a8 commit 6e40ce7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
2 changes: 0 additions & 2 deletions BlindspotAssistance/src/common/classes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class Vehicle
float getCruiseControl() {return cruiseControl; }
void calc_mocked_status(){
int elapsed_time = time(NULL) - current_time;
if (elapsed_time % 10 == 0)
std::cout << elapsed_time << " seconds has passed." << std::endl;

if (elapsed_time < 12)
parkingBrakeON = true;
Expand Down
16 changes: 8 additions & 8 deletions BlindspotAssistance/src/common/vehicle_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ enum class Modes {
highway
};

class vehicle_status
class VehicleStatus
{
private:
Modes mode = Modes::surveillance;
Modes mode = Modes::unknown;
bool engine_on, trailer_on, cruise_control_on;
Vehicle vehicle;
void setModeByFlag(){
Expand Down Expand Up @@ -49,18 +49,18 @@ class vehicle_status
mode = Modes::highway;
}
public:
Modes get_mode(){
calc_mode();
return mode;
}
std::string get_mode_to_string(){
void find_mode(){
if (!FLAGS_dm.empty())
setModeByFlag();
else{
vehicle.calc_mocked_status();
calc_mode();
}

}
Modes get_mode(){
return mode;
}
std::string get_mode_to_string(){
if( mode == Modes::parking )
return "Parking";
if( mode == Modes::reverse )
Expand Down
32 changes: 14 additions & 18 deletions BlindspotAssistance/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,20 @@ namespace
}
}

void alertHandler(size_t i, const Detection &f){
void alertHandler(size_t i, const Detection &f, VehicleStatus *vehicle){

std::string payload = std::to_string(i)+","+std::to_string(f.label)+","+std::to_string(f.confidence);
vehicle->find_mode();
std::string payload = std::to_string(i)+","+std::to_string(f.label)+","+std::to_string(f.confidence)+","+vehicle->get_mode_to_string();

int n = payload.length();

// declaring character array
char char_array[n + 1];

// copying the contents of the
// string to char array
// copying the contents of the string to char array
char char_array[payload.length() + 1];
strcpy(char_array, payload.c_str());

alertPublisher.sendAlert(char_array);

}

int areaDetectionCount(cv::Mat &img, const std::vector<Detection> &detections, size_t i, cv::Rect2d roi)
int areaDetectionCount(cv::Mat &img, const std::vector<Detection> &detections, size_t i, cv::Rect2d roi, VehicleStatus *vehicle)
{
int count = 0;

Expand All @@ -195,7 +192,7 @@ namespace

// Send alert if enable
if (FLAGS_alerts){
alertHandler(i+1, f);
alertHandler(i+1, f, vehicle);
}
}
}
Expand Down Expand Up @@ -280,10 +277,9 @@ namespace
}

void displayNSources(const std::vector<std::shared_ptr<VideoFrame>> &data,
float time,
const std::string &stats,
DisplayParams params,
Presenter &presenter)
float time, const std::string &stats,
DisplayParams params, Presenter &presenter,
VehicleStatus *vehicle)
{
cv::Mat windowImage = cv::Mat::zeros(params.windowSize, CV_8UC3);
auto loopBody = [&](size_t i) {
Expand All @@ -297,7 +293,7 @@ namespace
{
drawDetections(windowPart, elem->detections.get<std::vector<Detection>>());
}
camDetections[i] = areaDetectionCount(windowPart, elem->detections.get<std::vector<Detection>>(), i, roi[i]);
camDetections[i] = areaDetectionCount(windowPart, elem->detections.get<std::vector<Detection>>(), i, roi[i], vehicle);
}
};

Expand Down Expand Up @@ -378,7 +374,7 @@ int main(int argc, char *argv[])
{
try
{
vehicle_status vehicle;
VehicleStatus vehicle;
#if USE_TBB
TbbArenaWrapper arena;
#endif
Expand Down Expand Up @@ -535,7 +531,7 @@ int main(int argc, char *argv[])
std::unique_lock<std::mutex> lock(statMutex);
str = statStream.str();
}
displayNSources(result, averageFps, str, params, presenter);
displayNSources(result, averageFps, str, params, presenter, &vehicle);
int key = cv::waitKey(1);
presenter.handleKey(key);

Expand Down

0 comments on commit 6e40ce7

Please sign in to comment.