Skip to content

Commit 6f8ab32

Browse files
committed
new exp beacon guided aggreg
1 parent 7617ef2 commit 6f8ab32

File tree

2 files changed

+44
-54
lines changed

2 files changed

+44
-54
lines changed

loop-functions/gianduja/GiandujaBeaconAggregationLoopFunc.cpp

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ GiandujaBeaconAggregationLoopFunction::GiandujaBeaconAggregationLoopFunction() {
99
m_cCoordSpot2 = CVector2(-0.5,0.5);
1010
m_unCostSpot1 = 0;
1111
m_fObjectiveFunction = 0;
12-
m_Tbar = 0;
13-
m_State = 0;
1412
m_unTime = 0;
13+
m_unMesParam = 0;
14+
m_unMes = 0;
1515
}
1616

1717
/****************************************/
@@ -36,23 +36,37 @@ void GiandujaBeaconAggregationLoopFunction::Reset() {
3636
CoreLoopFunctions::Reset();
3737
m_unCostSpot1 = 0;
3838
m_fObjectiveFunction = 0;
39-
m_State = 0;
40-
m_Tbar = 0;
41-
m_unTime = 0;
42-
ExtractTime();
39+
if (m_unMesParam == 3) {
40+
m_unMes = m_pcRng->Uniform(CRange<UInt32>(0,2));
41+
}
42+
else {
43+
m_unMes = m_unMesParam;
44+
}
4345
PlaceBeacon();
4446
//PlaceLight();
4547
}
4648

4749

4850
void GiandujaBeaconAggregationLoopFunction::Init(TConfigurationNode& t_tree) {
4951
CoreLoopFunctions::Init(t_tree);
52+
TConfigurationNode cParametersNode;
53+
try {
54+
cParametersNode = GetNode(t_tree, "params");
55+
GetNodeAttributeOrDefault(cParametersNode, "mes", m_unMesParam, (UInt32) 3);
56+
} catch(std::exception e) {
57+
LOGERR << e.what() << std::endl;
58+
}
59+
if (m_unMesParam == 3) {
60+
m_unMes = m_pcRng->Uniform(CRange<UInt32>(0,2));
61+
}
62+
else {
63+
m_unMes = m_unMesParam;
64+
}
5065
//PlaceLight();
51-
ExtractTime();
5266
PlaceBeacon();
67+
SetMessageBeacon();
5368
}
5469

55-
5670
/****************************************/
5771
/****************************************/
5872

@@ -71,19 +85,6 @@ argos::CColor GiandujaBeaconAggregationLoopFunction::GetFloorColor(const argos::
7185
return CColor::GRAY50;
7286
}
7387

74-
75-
void GiandujaBeaconAggregationLoopFunction::ExtractTime() {
76-
try {
77-
CEPuckEntity& cEntity = dynamic_cast<CEPuckEntity&>(GetSpace().GetEntity("beacon0"));
78-
CEPuckBeacon& cController = dynamic_cast<CEPuckBeacon&>(cEntity.GetControllableEntity().GetController());
79-
m_Tbar = cController.getTBar();
80-
//LOG << "Time=" << m_Tbar << std::endl;
81-
} catch (std::exception& ex) {
82-
LOGERR << "Error while casting ExtractTime: " << ex.what() << std::endl;
83-
}
84-
}
85-
86-
8788
void GiandujaBeaconAggregationLoopFunction::PlaceBeacon() {
8889
try {
8990
CEPuckEntity& cEpuck = dynamic_cast<CEPuckEntity&>(GetSpace().GetEntity("beacon0"));
@@ -97,22 +98,16 @@ void GiandujaBeaconAggregationLoopFunction::PlaceBeacon() {
9798

9899
}
99100

100-
// void GiandujaBeaconAggregationLoopFunction::PlaceLight() {
101-
// // /* Place a light at a random spot to prevent robots to exploit (anti)phototaxis behaviours as RW */
102-
// CLightEntity& cLight = dynamic_cast<CLightEntity&>(GetSpace().GetEntity("light0"));
103-
// /* Consider the light only if it has non zero intensity */
104-
// cLight.SetIntensity(m_pcRng->Uniform(CRange<Real>(0.05f, 0.8f)));
105-
//
106-
// Real ab;
107-
// Real DistributionRadius = 1.3;
108-
//
109-
// ab = m_pcRng->Uniform(CRange<Real>(0.0f, 1.0f));
110-
// Real posX = DistributionRadius * cos(2 * CRadians::PI.GetValue() * ab);
111-
// Real posY = DistributionRadius * sin(2 * CRadians::PI.GetValue() * ab);
112-
//
113-
// cLight.MoveTo(CVector3(posX, posY, 0.4),CQuaternion().FromEulerAngles(m_pcRng->Uniform(CRange<CRadians>(CRadians::ZERO,CRadians::TWO_PI)),
114-
// CRadians::ZERO,CRadians::ZERO));
115-
// }
101+
void GiandujaBeaconAggregationLoopFunction::SetMessageBeacon() {
102+
try {
103+
CEPuckEntity& cEntity = dynamic_cast<CEPuckEntity&>(GetSpace().GetEntity("beacon0"));
104+
CEPuckBeacon& cController = dynamic_cast<CEPuckBeacon&>(cEntity.GetControllableEntity().GetController());
105+
cController.setMessage(m_unMes);
106+
//LOG << "Time=" << m_Tbar << std::endl;
107+
} catch (std::exception& ex) {
108+
LOGERR << "Error while casting SetMessageBeacon: " << ex.what() << std::endl;
109+
}
110+
}
116111

117112
CVector3 GiandujaBeaconAggregationLoopFunction::GetRandomPosition() {
118113
Real a;
@@ -134,22 +129,21 @@ void GiandujaBeaconAggregationLoopFunction::PostStep() {
134129
CSpace::TMapPerType& tEpuckMap = GetSpace().GetEntitiesByType("epuck");
135130
CVector2 cEpuckPosition(0,0);
136131

137-
if (m_unTime > m_Tbar) {
138-
m_State = 1;
139-
}
140-
141132
for (CSpace::TMapPerType::iterator it = tEpuckMap.begin(); it != tEpuckMap.end(); ++it) {
142133
CEPuckEntity* pcEpuck = any_cast<CEPuckEntity*>(it->second);
143134
cEpuckPosition.Set(pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetX(),
144135
pcEpuck->GetEmbodiedEntity().GetOriginAnchor().Position.GetY());
145136

146-
Real fDistanceSpot1 = (m_cCoordSpot1 - cEpuckPosition).Length();
147-
148-
if (m_State == 0 && fDistanceSpot1 <= m_fRadius) {
149-
m_unCostSpot1 += 2;
137+
Real fDistanceSpot;
138+
if (m_unMes == 0) {
139+
fDistanceSpot = (m_cCoordSpot1 - cEpuckPosition).Length();
150140
}
151-
else if (m_State == 1 && fDistanceSpot1 >= m_fRadius) {
152-
m_unCostSpot1 += 2;
141+
else if (m_unMes == 1) {
142+
fDistanceSpot = (m_cCoordSpot2 - cEpuckPosition).Length();
143+
}
144+
145+
if (fDistanceSpot >= m_fRadius) {
146+
m_unCostSpot1 += 1;
153147
}
154148
}
155149
m_fObjectiveFunction = (Real) m_unCostSpot1;
@@ -165,9 +159,6 @@ void GiandujaBeaconAggregationLoopFunction::PostExperiment() {
165159

166160
Real GiandujaBeaconAggregationLoopFunction::GetObjectiveFunction() {
167161
SInt32 score = 24000-m_fObjectiveFunction;
168-
if (score < 0) {
169-
score = 0;
170-
}
171162
return (score);
172163
}
173164

loop-functions/gianduja/GiandujaBeaconAggregationLoopFunc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ class GiandujaBeaconAggregationLoopFunction: public CoreLoopFunctions {
2424
virtual void PostStep();
2525

2626
Real GetObjectiveFunction();
27-
void PlaceLight();
28-
void ExtractTime();
2927
void PlaceBeacon();
28+
void SetMessageBeacon();
3029

3130
virtual CVector3 GetRandomPosition();
3231

@@ -36,9 +35,9 @@ class GiandujaBeaconAggregationLoopFunction: public CoreLoopFunctions {
3635
CVector2 m_cCoordSpot2;
3736

3837
UInt32 m_unCostSpot1;
39-
UInt32 m_Tbar;
40-
UInt8 m_State;
4138
Real m_fObjectiveFunction;
39+
UInt32 m_unMesParam;
40+
UInt8 m_unMes;
4241
UInt32 m_unTime;
4342
};
4443

0 commit comments

Comments
 (0)