Skip to content

Commit efafecc

Browse files
committed
Changes to primitive executor
1 parent c1e7086 commit efafecc

2 files changed

Lines changed: 18 additions & 36 deletions

File tree

src/software/embedded/primitive_executor.cpp

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
PrimitiveExecutor::PrimitiveExecutor(
1414
const Duration time_step, const robot_constants::RobotConstants& robot_constants,
1515
const TeamColour friendly_team_colour, const RobotId robot_id)
16-
: current_primitive_(),
17-
friendly_team_colour_(friendly_team_colour),
16+
: friendly_team_colour_(friendly_team_colour),
1817
robot_constants_(robot_constants),
1918
time_step_(time_step),
2019
robot_id_(robot_id)
@@ -64,28 +63,24 @@ void PrimitiveExecutor::updatePrimitive(const TbotsProto::Primitive& primitive_m
6463
createTrajectoryPathFromParams(current_primitive_.move().xy_traj_params(),
6564
position_, velocity_, robot_constants_);
6665

67-
// Check if this new trajectory is "new". That is, if its destination differs
68-
// meaningfully from our current trajectory.
6966
if (isLinearTrajectoryNew(new_trajectory_path))
7067
{
7168
trajectory_path_ = new_trajectory_path;
7269
time_since_linear_trajectory_creation_ = Duration::fromSeconds(RTT_S);
7370
x_pid.reset();
7471
y_pid.reset();
75-
LOG(INFO) << "new linear trajectory accepted";
7672
}
7773

7874
const BangBangTrajectory1DAngular new_angular_trajectory =
7975
createAngularTrajectoryFromParams(current_primitive_.move().w_traj_params(),
8076
orientation_, angular_velocity_,
8177
robot_constants_);
82-
LOG(INFO) << "angular has val " << angular_trajectory_.has_value();
78+
8379
if (isAngularTrajectoryNew(new_angular_trajectory))
8480
{
8581
angular_trajectory_ = new_angular_trajectory;
8682
time_since_angular_trajectory_creation_ = Duration::fromSeconds(RTT_S);
8783
w_pid.reset();
88-
LOG(INFO) << "new angular trajectory accepted";
8984
}
9085
}
9186
}
@@ -138,7 +133,7 @@ void PrimitiveExecutor::updateState(const Point& position, const Vector& velocit
138133
}
139134
}
140135

141-
Vector PrimitiveExecutor::getTargetLinearVelocity()
136+
Vector PrimitiveExecutor::getTargetLinearVelocity() const
142137
{
143138
Vector target_velocity =
144139
trajectory_path_->getVelocity(time_since_linear_trajectory_creation_.toSeconds());
@@ -158,7 +153,7 @@ Vector PrimitiveExecutor::getTargetLinearVelocity()
158153
return target_velocity;
159154
}
160155

161-
AngularVelocity PrimitiveExecutor::getTargetAngularVelocity()
156+
AngularVelocity PrimitiveExecutor::getTargetAngularVelocity() const
162157
{
163158
AngularVelocity angular_velocity = angular_trajectory_->getVelocity(
164159
time_since_angular_trajectory_creation_.toSeconds());
@@ -229,10 +224,6 @@ std::unique_ptr<TbotsProto::DirectControlPrimitive> PrimitiveExecutor::stepPrimi
229224
globalToLocalVelocity({x_pid_close.step(error_linear.x()),
230225
y_pid_close.step(error_linear.y())},
231226
orientation_);
232-
LOG(INFO) << "Y: close to target, doing pure PID with effort "
233-
<< target_linear_velocity.y();
234-
LOG(INFO) << "X: close to target, doing pure PID with effort "
235-
<< target_linear_velocity.x();
236227
}
237228
else
238229
{
@@ -243,21 +234,14 @@ std::unique_ptr<TbotsProto::DirectControlPrimitive> PrimitiveExecutor::stepPrimi
243234
position_;
244235
const Vector pid_effort_linear(x_pid.step(error_linear.x()),
245236
y_pid.step(error_linear.y()));
246-
LOG(INFO) << "Y: far from target, PID control effort: "
247-
<< pid_effort_linear.y()
248-
<< " FF: " << trajectory_linear_velocity.y();
249-
LOG(INFO) << "X: far from target, PID control effort: "
250-
<< pid_effort_linear.x()
251-
<< " FF: " << trajectory_linear_velocity.x();
252237
target_linear_velocity = globalToLocalVelocity(
253238
trajectory_linear_velocity + pid_effort_linear, orientation_);
254239
}
240+
255241
if (error_angular.abs().toDegrees() < ANGULAR_PURE_PID_THRESHOLD_DEGREES)
256242
{
257243
target_angular_velocity = AngularVelocity::fromRadians(
258244
w_pid_close.step(error_angular.toRadians()));
259-
LOG(INFO) << "AND: close to target, doing pure PID with effort: "
260-
<< target_angular_velocity.toDegrees();
261245
}
262246
else
263247
{
@@ -273,14 +257,8 @@ std::unique_ptr<TbotsProto::DirectControlPrimitive> PrimitiveExecutor::stepPrimi
273257
AngularVelocity::fromRadians(w_pid.step(error_angular.toRadians()));
274258
target_angular_velocity =
275259
(trajectory_angular_velocity + pid_effort_angular);
276-
LOG(INFO) << "AND: far from target, PID control effort: "
277-
<< pid_effort_angular.toDegrees()
278-
<< " FF: " << trajectory_angular_velocity.toDegrees();
279260
}
280261

281-
LOG(INFO) << "Local velocity x " << target_linear_velocity.x() << " y "
282-
<< target_linear_velocity.y();
283-
284262
// Make sure target linear velocity is clamped
285263
target_linear_velocity = target_linear_velocity.normalize(
286264
std::min(target_linear_velocity.length(),
@@ -291,7 +269,6 @@ std::unique_ptr<TbotsProto::DirectControlPrimitive> PrimitiveExecutor::stepPrimi
291269
convertDribblerModeToDribblerSpeed(
292270
current_primitive_.move().dribbler_mode(), robot_constants_),
293271
current_primitive_.move().auto_chip_or_kick());
294-
LOG(INFO) << "handle kmove end";
295272

296273
return std::make_unique<TbotsProto::DirectControlPrimitive>(
297274
prim->direct_control());

src/software/embedded/primitive_executor.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ class PrimitiveExecutor
5555
TbotsProto::PrimitiveExecutorStatus& status);
5656

5757
private:
58-
/*
59-
* Compute the next target linear _local_ velocity the robot should be at.
60-
* @returns Vector The target linear _local_ velocity
61-
*/
62-
Vector getTargetLinearVelocity();
63-
6458
/**
59+
* Check if the given trajectory is "new". That is, if its destination differs
60+
* meaningfully from our current trajectory.
6561
*
6662
* @param new_trajectory The new trajectory requested by the AI.
6763
* @return True if the new trajectory requested is meaningfully different from the
@@ -70,19 +66,28 @@ class PrimitiveExecutor
7066
bool isLinearTrajectoryNew(const std::optional<TrajectoryPath>& new_trajectory) const;
7167

7268
/**
69+
* Check if the given trajectory is "new". That is, if its destination differs
70+
* meaningfully from our current trajectory.
7371
*
7472
* @param new_trajectory The new trajectory requested by the AI.
7573
* @return True if the new trajectory requested is meaningfully different from the
7674
* current trajectory. That is, if the destinations are new.
7775
*/
7876
bool isAngularTrajectoryNew(const BangBangTrajectory1DAngular& new_trajectory) const;
7977

78+
/**
79+
* Compute the next target linear _local_ velocity the robot should be at.
80+
*
81+
* @returns Vector The target linear _local_ velocity
82+
*/
83+
Vector getTargetLinearVelocity() const;
84+
8085
/*
81-
* Returns the next target angular velocity the robot
86+
* Returns the next target angular velocity the robot should be at.
8287
*
8388
* @returns AngularVelocity The target angular velocity
8489
*/
85-
AngularVelocity getTargetAngularVelocity();
90+
AngularVelocity getTargetAngularVelocity() const;
8691

8792
TbotsProto::Primitive current_primitive_;
8893

0 commit comments

Comments
 (0)