Skip to content

Commit c6ffd2e

Browse files
author
jschlind411
committed
Fixed Pickup Math
Fixed issue in PickupController.cpp where math was incorrectly being done in an incorrect location in the code. This resulted in the rover not attempting to change orientation when attempting to pickup cube
1 parent bc9374d commit c6ffd2e

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/behaviours/src/PickUpController.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ PickUpController::PickUpController() {
2222
PickUpController::~PickUpController() {
2323
}
2424

25-
void PickUpController::SetTagData(vector<Tag> tags) {
25+
void PickUpController::SetTagData(vector<Tag> tags)
26+
{
2627

2728
if (tags.size() > 0) {
2829

@@ -61,18 +62,35 @@ void PickUpController::SetTagData(vector<Tag> tags) {
6162

6263
float cameraOffsetCorrection = 0.023; //meters;
6364

65+
///TODO: Explain the trig going on here- blockDistance is c, 0.195 is b; find a
66+
blockDistanceFromCamera = hypot(hypot(tags[target].getPositionX(), tags[target].getPositionY()), tags[target].getPositionZ());
67+
68+
//WRONG WRONG WRONG WRONG
69+
//blockDistance = hypot(tags[target].getPositionZ(), tags[target].getPositionY()); //distance from bottom center of chassis ignoring height.
70+
71+
if ( (blockDistanceFromCamera*blockDistanceFromCamera - 0.195*0.195) > 0 )
72+
{
73+
blockDistance = sqrt(blockDistanceFromCamera*blockDistanceFromCamera - 0.195*0.195);
74+
}
75+
else
76+
{
77+
float epsilon = 0.00001; // A small non-zero positive number
78+
blockDistance = epsilon;
79+
}
80+
81+
//cout << "blockDistance TAGDATA: " << blockDistance << endl;
82+
6483
blockYawError = atan((tags[target].getPositionX() + cameraOffsetCorrection)/blockDistance)*1.05; //angle to block from bottom center of chassis on the horizontal.
6584

66-
///TODO: Explain the trig going on here- blockDistance is c, 0.195 is b; find a
67-
blockDistance = hypot(tags[target].getPositionX(), tags[target].getPositionY()); //distance from bottom center of chassis ignoring height.
85+
cout << "blockYawError TAGDATA: " << blockYawError << endl;
6886

69-
blockDistanceFromCamera = hypot(hypot(tags[target].getPositionX(), tags[target].getPositionY()), tags[target].getPositionZ());
7087
}
7188

7289
}
7390

7491

75-
bool PickUpController::SetSonarData(float rangeCenter){
92+
bool PickUpController::SetSonarData(float rangeCenter)
93+
{
7694

7795
if (rangeCenter < 0.12 && targetFound) {
7896
result.type = behavior;
@@ -86,31 +104,23 @@ bool PickUpController::SetSonarData(float rangeCenter){
86104

87105
}
88106

89-
void PickUpController::ProcessData() {
90-
if(!targetFound){
107+
void PickUpController::ProcessData()
108+
{
109+
if(!targetFound)
110+
{
91111
// Do nothing
92112
return;
93113
}
94114

95-
if ( (blockDistance*blockDistance - 0.195*0.195) > 0 )
96-
{
97-
blockDistance = sqrt(blockDistance*blockDistance - 0.195*0.195);
98-
}
99-
else
100-
{
101-
float epsilon = 0.00001; // A small non-zero positive number
102-
blockDistance = epsilon;
103-
}
104-
105115
//if target is close enough
106116
//diffrence between current time and millisecond time
107117
long int Tdiff = current_time - millTimer;
108118
float Td = Tdiff/1e3;
109119

110-
cout << "distance : " << blockDistanceFromCamera << " time is : " << Td << endl;
111-
112-
if (blockDistanceFromCamera < 0.14 && Td < 3.9) {
120+
//cout << "distance : " << blockDistanceFromCamera << " time is : " << Td << endl;
113121

122+
if (blockDistanceFromCamera < 0.14 && Td < 3.9)
123+
{
114124
result.type = behavior;
115125
result.b = nextProcess;
116126
result.reset = true;
@@ -203,6 +213,8 @@ Result PickUpController::DoWork() {
203213
float lower_gripper_time_begin = 4.0;
204214
float target_reaquire_begin= 4.2;
205215
float target_pickup_task_time_limit = 4.8;
216+
217+
//cout << "blockDistance DOWORK: " << blockDistance << endl;
206218

207219
if (nTargetsSeen == 0 && !lockTarget)
208220
{

0 commit comments

Comments
 (0)