Skip to content

Commit 1f5559a

Browse files
committed
add aimpoint
1 parent 250c00c commit 1f5559a

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ services: # Must be present exactly once at the beginning of the docker-compo
66
ipc: host
77
environment:
88
- DISPLAY=$DISPLAY
9-
command: "/usr/bin/cfsd19-cognition-detectconelane --cid=219 --verbose --freq=10"
9+
command: "cfsd-logic-pathplanner --cid=253 --debug --freq=10"
10+
11+
cfsd19-logic-aimpoint:
12+
image: lowitz/aimpoint:v0.0.2
13+
network_mode: "host"
14+
command: "cfsd-logic-aimpoint --cid=253 --previewTime=0.5 --verbose"

src/cfsd-logic-pathplanner.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ int32_t main(int32_t argc, char **argv) {
4141
bool const verbose{commandlineArguments.count("verbose") != 0};
4242
uint32_t localPathSenderId = 2601;
4343

44-
Collector collector(commandlineArguments);
45-
4644
cluon::OD4Session od4{
4745
static_cast<uint16_t>(std::stoi(commandlineArguments["cid"]))};
48-
46+
Collector collector(od4, commandlineArguments);
47+
4948
auto onObjectFrameStart{[&planner = collector](
5049
cluon::data::Envelope &&envelope)
5150
{
@@ -88,6 +87,12 @@ int32_t main(int32_t argc, char **argv) {
8887
planner.getEquilibrioception(envelope);
8988
}};
9089

90+
auto onAimpoint{[&planner = collector](
91+
cluon::data::Envelope &&envelope)
92+
{
93+
planner.getAimpoint(envelope);
94+
}};
95+
9196
auto atFrequency{[&od4, &verbose, &collector, &localPathSenderId]() -> bool
9297
{
9398
{
@@ -144,6 +149,9 @@ int32_t main(int32_t argc, char **argv) {
144149
onObjectPosition);
145150
od4.dataTrigger(opendlv::logic::sensation::Equilibrioception::ID(),
146151
onEquilibrioception);
152+
153+
od4.dataTrigger(opendlv::logic::action::AimPoint::ID(),
154+
onAimpoint);
147155
od4.timeTrigger(std::stoi(commandlineArguments["freq"]), atFrequency);
148156

149157
retCode = 0;

src/collector.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ Eigen::ArrayXXf getDisplacementTranslation(std::vector<Point2D> pastCones, std::
5454
return vec;
5555
}
5656
/*-------------------------------------------------------*/
57-
Collector::Collector(std::map<std::string, std::string> commandlineArguments) :
57+
Collector::Collector(cluon::OD4Session &od4, std::map<std::string, std::string> commandlineArguments) :
58+
m_od4(od4),
5859
m_pastBlue{},
5960
m_pastYellow{},
6061
m_Cones{},
@@ -77,7 +78,9 @@ Collector::Collector(std::map<std::string, std::string> commandlineArguments) :
7778
currentCompleteFrameId(),
7879

7980
frameStart(),
80-
frameEnd()
81+
frameEnd(),
82+
83+
currentAim()
8184

8285
{
8386
m_verbose = static_cast<bool>(commandlineArguments.count("verbose") != 0);
@@ -595,6 +598,13 @@ void Collector::ShowResult(std::vector<Cone> blue, std::vector<Cone> yellow, std
595598
}
596599
}
597600

601+
//Show aimpoint from Aimpoint module
602+
//current aimpoint
603+
int xt = int(currentAim.x * float(resultResize) + outWidth/2);
604+
int yt = int(currentAim.y * float(resultResize));
605+
cv::Scalar aimpointColor(0,0,255);
606+
cv::circle(outImg, cv::Point(xt,-yt+outHeight-heightOffset), 4, aimpointColor, -1);
607+
598608
// Show result image
599609
cv::imshow("detectconelane-blue-yellow", outImg);
600610
cv::imshow("detectconelane-orange", outImgOrange);
@@ -706,3 +716,18 @@ void Collector::getEquilibrioception(cluon::data::Envelope envelope){
706716
<< yawRate << std::endl;
707717
}
708718
}
719+
720+
void Collector::getAimpoint(cluon::data::Envelope envelope){
721+
opendlv::logic::action::AimPoint msg =
722+
cluon::extractMessage<opendlv::logic::action::AimPoint>(
723+
std::move(envelope));
724+
725+
float angle = msg.azimuthAngle();
726+
float distance = msg.distance();
727+
currentAim.x = distance*cos(angle);
728+
currentAim.y = distance*sin(angle);
729+
if (m_verbose) {
730+
std::cout << "Got AIMPOINT for object with id=" << 0
731+
<< " and x=" << currentAim.x << " y=" << currentAim.y << std::endl;
732+
}
733+
}

src/collector.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct Point2D {
4242

4343
class Collector{
4444
public:
45-
Collector(std::map<std::string, std::string>);
45+
Collector(cluon::OD4Session &od4, std::map<std::string, std::string>);
4646
~Collector() = default;
4747

4848
// CFSD19 modification
@@ -61,19 +61,25 @@ class Collector{
6161
void ShowResult(std::vector<Cone> blue, std::vector<Cone> yellow, std::vector<Cone> orange, std::vector<Point2D> PredictedBlues, std::vector<Point2D> PredictedYellows);
6262

6363
public:
64+
cluon::OD4Session &m_od4;
65+
//Containers for path planning
6466
std::vector<Point2D> m_pastBlue;
6567
std::vector<Point2D> m_pastYellow;
6668
std::queue<Cone*> m_Cones;
6769
std::queue<Cone> m_currentConeFrame;
6870
std::vector<Point2D> middlePath;
6971

72+
//Counters
7073
uint32_t m_collectorFrameCounter;
7174
uint32_t m_currentFrameCounter;
75+
76+
//Flags and status
7277
Status m_status;
7378
bool m_isSkidpad;
7479
bool m_verbose;
7580
bool m_debug;
7681

82+
//Variables for creating cone frames
7783
std::mutex uncompleteFrameMutex;
7884
std::map<uint32_t, Cone> uncompleteFrame;
7985
uint32_t currentUncompleteFrameId;
@@ -84,13 +90,18 @@ class Collector{
8490

8591
cluon::data::TimeStamp frameStart;
8692
cluon::data::TimeStamp frameEnd;
87-
93+
Point2D currentAim;
94+
//Function for creating cone frames
8895
void getObjectFrameStart(cluon::data::Envelope envelope);
8996
void getObjectFrameEnd(cluon::data::Envelope envelope);
9097
void getObject(cluon::data::Envelope envelope);
9198
void getObjectType(cluon::data::Envelope envelope);
9299
void getObjectPosition(cluon::data::Envelope envelope);
93100
void getEquilibrioception(cluon::data::Envelope envelope);
101+
102+
//Visualiztion of aimpoints fro debugging
103+
void getAimpoint(cluon::data::Envelope envelope);
104+
94105
};
95106

96107
#endif

0 commit comments

Comments
 (0)