Skip to content

Commit d5ad87d

Browse files
committed
Naming consistency
1 parent a8c1320 commit d5ad87d

9 files changed

Lines changed: 64 additions & 66 deletions

File tree

crates/step_planning/src/loss_fields/path_distance.rs renamed to crates/step_planning/src/cost_fields/path_distance.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub struct PathDistanceField<'a> {
99
}
1010

1111
impl PathDistanceField<'_> {
12-
pub fn loss(&self, point: Point2<Ground>) -> f32 {
12+
pub fn cost(&self, point: Point2<Ground>) -> f32 {
1313
let projection = self.path.project(point);
1414

1515
let projection_to_point = point - projection;
@@ -36,7 +36,7 @@ mod tests {
3636
use linear_algebra::{point, vector, Orientation2, Vector2};
3737
use types::planned_path::{Path, PathSegment};
3838

39-
use crate::loss_fields::path_distance::PathDistanceField;
39+
use crate::cost_fields::path_distance::PathDistanceField;
4040

4141
fn test_path() -> Vec<PathSegment> {
4242
vec![
@@ -56,66 +56,66 @@ mod tests {
5656

5757
#[test]
5858
fn test_path_distance() {
59-
let loss_field = PathDistanceField {
59+
let cost_field = PathDistanceField {
6060
path: Path {
6161
segments: &test_path(),
6262
},
6363
};
6464

6565
// Start
6666
let sample_point_1 = point![0.0, 0.0];
67-
let loss_1 = loss_field.loss(sample_point_1);
68-
let grad_1 = loss_field.grad(sample_point_1);
67+
let cost_1 = cost_field.cost(sample_point_1);
68+
let grad_1 = cost_field.grad(sample_point_1);
6969

70-
assert_abs_diff_eq!(loss_1, 0.0);
70+
assert_abs_diff_eq!(cost_1, 0.0);
7171
assert_abs_diff_eq!(grad_1, Vector2::zeros());
7272

7373
// Before start
7474
let sample_point_2 = point![-1.0, 0.0];
75-
let loss_2 = loss_field.loss(sample_point_2);
76-
let grad_2 = loss_field.grad(sample_point_2);
75+
let cost_2 = cost_field.cost(sample_point_2);
76+
let grad_2 = cost_field.grad(sample_point_2);
7777

78-
assert_abs_diff_eq!(loss_2, 1.0);
78+
assert_abs_diff_eq!(cost_2, 1.0);
7979
assert_abs_diff_eq!(grad_2, vector![-2.0, 0.0]);
8080

8181
// End of first line segment, start of arc
8282
let sample_point_3 = point![3.0, 0.0];
83-
let loss_3 = loss_field.loss(sample_point_3);
84-
let grad_3 = loss_field.grad(sample_point_3);
83+
let cost_3 = cost_field.cost(sample_point_3);
84+
let grad_3 = cost_field.grad(sample_point_3);
8585

86-
assert_abs_diff_eq!(loss_3, 0.0);
86+
assert_abs_diff_eq!(cost_3, 0.0);
8787
assert_abs_diff_eq!(grad_3, Vector2::zeros());
8888

8989
// Below start of arc
9090
let sample_point_4 = point![3.0, -1.0];
91-
let loss_4 = loss_field.loss(sample_point_4);
92-
let grad_4 = loss_field.grad(sample_point_4);
91+
let cost_4 = cost_field.cost(sample_point_4);
92+
let grad_4 = cost_field.grad(sample_point_4);
9393

94-
assert_abs_diff_eq!(loss_4, 1.0);
94+
assert_abs_diff_eq!(cost_4, 1.0);
9595
assert_abs_diff_eq!(grad_4, vector![0.0, -2.0]);
9696

9797
// End of arc
9898
let sample_point_5 = point![4.0, 1.0];
99-
let loss_5 = loss_field.loss(sample_point_5);
100-
let grad_5 = loss_field.grad(sample_point_5);
99+
let cost_5 = cost_field.cost(sample_point_5);
100+
let grad_5 = cost_field.grad(sample_point_5);
101101

102-
assert_abs_diff_eq!(loss_5, 0.0);
102+
assert_abs_diff_eq!(cost_5, 0.0);
103103
assert_abs_diff_eq!(grad_5, Vector2::zeros());
104104

105105
// End
106106
let sample_point_6 = point![4.0, 4.0];
107-
let loss_6 = loss_field.loss(sample_point_6);
108-
let grad_6 = loss_field.grad(sample_point_6);
107+
let cost_6 = cost_field.cost(sample_point_6);
108+
let grad_6 = cost_field.grad(sample_point_6);
109109

110-
assert_abs_diff_eq!(loss_6, 0.0);
110+
assert_abs_diff_eq!(cost_6, 0.0);
111111
assert_abs_diff_eq!(grad_6, Vector2::zeros());
112112

113113
// Outside of arc
114114
let sample_point_7 = point![4.0, 0.0];
115-
let loss_7 = loss_field.loss(sample_point_7);
116-
let grad_7 = loss_field.grad(sample_point_7);
115+
let cost_7 = cost_field.cost(sample_point_7);
116+
let grad_7 = cost_field.grad(sample_point_7);
117117

118-
assert_abs_diff_eq!(loss_7, (SQRT_2 - 1.0).powi(2));
118+
assert_abs_diff_eq!(cost_7, (SQRT_2 - 1.0).powi(2));
119119
assert_abs_diff_eq!(grad_7, vector![2.0 - SQRT_2, -(2.0 - SQRT_2)]);
120120
}
121121
}

crates/step_planning/src/loss_fields/path_progress.rs renamed to crates/step_planning/src/cost_fields/path_progress.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct PathProgressField<'a> {
1313
}
1414

1515
impl PathProgressField<'_> {
16-
pub fn loss(&self, point: Point2<Ground>) -> f32 {
16+
pub fn cost(&self, point: Point2<Ground>) -> f32 {
1717
let progress = self.path.progress(point);
1818

1919
let clamped_progress = smoothmin(progress, self.path.length(), self.smoothness);
@@ -41,7 +41,7 @@ mod tests {
4141
use linear_algebra::{point, vector, Orientation2};
4242
use types::planned_path::{Path, PathSegment};
4343

44-
use crate::loss_fields::path_progress::PathProgressField;
44+
use crate::cost_fields::path_progress::PathProgressField;
4545

4646
fn test_path() -> Vec<PathSegment> {
4747
vec![
@@ -61,7 +61,7 @@ mod tests {
6161

6262
#[test]
6363
fn test_path_progress() {
64-
let loss_field = PathProgressField {
64+
let cost_field = PathProgressField {
6565
path: Path {
6666
segments: &test_path(),
6767
},
@@ -70,57 +70,57 @@ mod tests {
7070

7171
// Start
7272
let sample_point_1 = point![0.0, 0.0];
73-
let loss_1 = loss_field.loss(sample_point_1);
74-
let grad_1 = loss_field.grad(sample_point_1);
73+
let cost_1 = cost_field.cost(sample_point_1);
74+
let grad_1 = cost_field.grad(sample_point_1);
7575

7676
assert_abs_diff_eq!(grad_1, vector![-1.0, 0.0]);
7777

7878
// Before start
7979
let sample_point_2 = point![-1.0, 0.0];
80-
let loss_2 = loss_field.loss(sample_point_2);
81-
let grad_2 = loss_field.grad(sample_point_2);
80+
let cost_2 = cost_field.cost(sample_point_2);
81+
let grad_2 = cost_field.grad(sample_point_2);
8282

83-
assert_abs_diff_eq!(loss_2 - loss_1, 1.0, epsilon = 1e-6);
83+
assert_abs_diff_eq!(cost_2 - cost_1, 1.0, epsilon = 1e-6);
8484
assert_abs_diff_eq!(grad_2, vector![-1.0, 0.0]);
8585

8686
// End of first line segment, start of arc
8787
let sample_point_3 = point![3.0, 0.0];
88-
let loss_3 = loss_field.loss(sample_point_3);
89-
let grad_3 = loss_field.grad(sample_point_3);
88+
let cost_3 = cost_field.cost(sample_point_3);
89+
let grad_3 = cost_field.grad(sample_point_3);
9090

91-
assert_abs_diff_eq!(loss_3 - loss_1, -3.0);
91+
assert_abs_diff_eq!(cost_3 - cost_1, -3.0);
9292
assert_abs_diff_eq!(grad_3, vector![-1.0, 0.0]);
9393

9494
// Below start of arc
9595
let sample_point_4 = point![3.0, -1.0];
96-
let loss_4 = loss_field.loss(sample_point_4);
97-
let grad_4 = loss_field.grad(sample_point_4);
96+
let cost_4 = cost_field.cost(sample_point_4);
97+
let grad_4 = cost_field.grad(sample_point_4);
9898

99-
assert_abs_diff_eq!(loss_4, loss_3);
99+
assert_abs_diff_eq!(cost_4, cost_3);
100100
assert_abs_diff_eq!(grad_4, grad_3);
101101

102102
// End of arc
103103
let sample_point_5 = point![4.0, 1.0];
104-
let loss_5 = loss_field.loss(sample_point_5);
105-
let grad_5 = loss_field.grad(sample_point_5);
104+
let cost_5 = cost_field.cost(sample_point_5);
105+
let grad_5 = cost_field.grad(sample_point_5);
106106

107-
assert_abs_diff_eq!(loss_5, loss_3 - FRAC_PI_2);
107+
assert_abs_diff_eq!(cost_5, cost_3 - FRAC_PI_2);
108108
assert_abs_diff_eq!(grad_5, vector![0.0, -1.0]);
109109

110110
// End
111111
let sample_point_6 = point![4.0, 4.0];
112-
let loss_6 = loss_field.loss(sample_point_6);
113-
let grad_6 = loss_field.grad(sample_point_6);
112+
let cost_6 = cost_field.cost(sample_point_6);
113+
let grad_6 = cost_field.grad(sample_point_6);
114114

115-
assert!(((loss_5 - 3.0)..(loss_5 - 2.0)).contains(&loss_6));
115+
assert!(((cost_5 - 3.0)..(cost_5 - 2.0)).contains(&cost_6));
116116
assert_abs_diff_eq!(grad_6, vector![0.0, 0.0]);
117117

118118
// Outside of arc
119119
let sample_point_7 = point![4.0, 0.0];
120-
let loss_7 = loss_field.loss(sample_point_7);
121-
let grad_7 = loss_field.grad(sample_point_7);
120+
let cost_7 = cost_field.cost(sample_point_7);
121+
let grad_7 = cost_field.grad(sample_point_7);
122122

123-
assert_abs_diff_eq!(loss_7, loss_3 - FRAC_PI_4, epsilon = 1e-6);
123+
assert_abs_diff_eq!(cost_7, cost_3 - FRAC_PI_4, epsilon = 1e-6);
124124
assert_abs_diff_eq!(grad_7, vector![-0.5, -0.5]);
125125
}
126126
}

crates/step_planning/src/loss_fields/step_size.rs renamed to crates/step_planning/src/cost_fields/step_size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn penalty_function_derivative(walk_volume_value: f32) -> f32 {
141141
}
142142

143143
impl StepSizeField {
144-
pub fn loss(&self, step: StepAndSupportFoot<f32>) -> f32 {
144+
pub fn cost(&self, step: StepAndSupportFoot<f32>) -> f32 {
145145
let value = walk_volume(&step, &self.walk_volume_coefficients);
146146

147147
penalty_function(value)

crates/step_planning/src/loss_fields/target_orientation.rs renamed to crates/step_planning/src/cost_fields/target_orientation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct TargetOrientationField<'a> {
1515
}
1616

1717
impl TargetOrientationField<'_> {
18-
pub fn loss(&self, pose: Pose<f32>) -> f32 {
18+
pub fn cost(&self, pose: Pose<f32>) -> f32 {
1919
let progress = self.path.progress(pose.position);
2020
let path_length = self.path.length();
2121

crates/step_planning/src/loss_fields/walk_orientation.rs renamed to crates/step_planning/src/cost_fields/walk_orientation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct WalkOrientationField {
1212
}
1313

1414
impl WalkOrientationField {
15-
pub fn loss(&self, pose: Pose<f32>) -> f32 {
15+
pub fn cost(&self, pose: Pose<f32>) -> f32 {
1616
match self.orientation_mode {
1717
OrientationMode::Unspecified => 0.0,
1818
OrientationMode::LookTowards(orientation) => {

crates/step_planning/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
pub mod cost_fields;
12
pub mod geometry;
2-
pub mod loss_fields;
33
pub mod step_plan;
44
pub mod traits;
55
pub mod utils;

crates/step_planning/src/step_plan.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use types::{
1111
};
1212

1313
use crate::{
14-
geometry::{angle::Angle, pose::PoseAndSupportFoot, Pose},
15-
loss_fields::{
14+
cost_fields::{
1615
path_distance::PathDistanceField,
1716
path_progress::PathProgressField,
1817
step_size::{StepSizeField, WalkVolumeCoefficients},
1918
target_orientation::TargetOrientationField,
2019
walk_orientation::WalkOrientationField,
2120
},
21+
geometry::{angle::Angle, pose::PoseAndSupportFoot, Pose},
2222
};
2323

2424
pub struct StepPlan<'a, T>(&'a [T]);
@@ -83,13 +83,13 @@ impl StepPlanning<'_> {
8383
} = *self.parameters;
8484
let PlannedStep { pose, step } = planned_step;
8585

86-
let path_progress_cost = self.path_progress().loss(pose.position) * path_progress_reward;
87-
let path_distance_cost = self.path_distance().loss(pose.position) * path_distance_penalty;
86+
let path_progress_cost = self.path_progress().cost(pose.position) * path_progress_reward;
87+
let path_distance_cost = self.path_distance().cost(pose.position) * path_distance_penalty;
8888
let walk_orientation_cost =
89-
self.walk_orientation().loss(pose.clone()) * walk_orientation_penalty;
89+
self.walk_orientation().cost(pose.clone()) * walk_orientation_penalty;
9090
let target_orientation_cost =
91-
self.target_orientation().loss(pose) * target_orientation_penalty;
92-
let step_size_cost = self.step_size().loss(step) * step_size_penalty;
91+
self.target_orientation().cost(pose) * target_orientation_penalty;
92+
let step_size_cost = self.step_size().cost(step) * step_size_penalty;
9393

9494
path_progress_cost
9595
+ path_distance_cost

crates/step_planning_solver/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl LeastSquaresProblem<f32, U1, Dyn> for StepPlanningProblem<'_> {
5454
fn residuals(&self) -> Option<nalgebra::Vector<f32, U1, Self::ResidualStorage>> {
5555
let step_plan = StepPlan::from(self.variables.as_slice());
5656

57-
let loss = self
57+
let cost = self
5858
.step_planning
5959
.planned_steps(
6060
self.step_planning
@@ -66,9 +66,9 @@ impl LeastSquaresProblem<f32, U1, Dyn> for StepPlanningProblem<'_> {
6666
.map(|planned_step| self.step_planning.cost(planned_step))
6767
.sum();
6868

69-
// eprintln!("loss: {loss}\n\t({:.4?})", self.variables.as_slice());
69+
// eprintln!("cost: {cost}\n\t({:.4?})", self.variables.as_slice());
7070

71-
Some(vector![loss])
71+
Some(vector![cost])
7272
}
7373

7474
fn jacobian(&self) -> Option<nalgebra::Matrix<f32, U1, Dyn, Self::JacobianStorage>> {
@@ -98,11 +98,9 @@ impl LeastSquaresProblem<f32, U1, Dyn> for StepPlanningProblem<'_> {
9898
})
9999
.sum();
100100

101-
// let step_planning_loss = self.step_planning.loss_field();
102-
103101
// let step_plan = StepPlan::from(self.variables.as_slice());
104102

105-
// let loss: f32 = self
103+
// let cost: f32 = self
106104
// .step_planning
107105
// .planned_steps(
108106
// self.step_planning
@@ -111,11 +109,11 @@ impl LeastSquaresProblem<f32, U1, Dyn> for StepPlanningProblem<'_> {
111109
// .with_support_foot(self.step_planning.initial_support_foot),
112110
// &step_plan,
113111
// )
114-
// .map(|planned_step| step_planning_loss.loss(planned_step))
112+
// .map(|planned_step| self.step_planning.cost(planned_step))
115113
// .sum();
116114

117115
// eprintln!(
118-
// "grad: {loss}\n\t({:.4?})\n\t[{:.4?}]",
116+
// "grad: {cost}\n\t({:.4?})\n\t[{:.4?}]",
119117
// self.variables.as_slice(),
120118
// &gradient.as_slice()
121119
// );

0 commit comments

Comments
 (0)