Skip to content

Commit b147382

Browse files
committed
limiting max forces by m*g for stability reasons, using trajectory discount factor gamma=0.9 by default
1 parent 6523787 commit b147382

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

Diff for: monoforce/scripts/train.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
MODEL=lss # lss, lidarbev, bevfusion
44
ROBOT=marv
5-
DEBUG=False
5+
DEBUG=True
66
VIS=False
7-
BSZ=32 # 32, 32, 8
7+
BSZ=4 # 32, 32, 8
88
WEIGHTS=$HOME/workspaces/traversability_ws/src/monoforce/monoforce/config/weights/${MODEL}/val.pth
99

1010
source $HOME/workspaces/traversability_ws/devel/setup.bash
1111
./train.py --bsz $BSZ --nepochs 1000 --lr 1e-3 --weight_decay 1e-7 \
1212
--debug $DEBUG --vis $VIS \
1313
--geom_weight 1.0 --terrain_weight 2.0 --phys_weight 1.0 \
14-
--traj_sim_time 4.0 \
14+
--traj_sim_time 5.0 \
1515
--robot $ROBOT \
1616
--model $MODEL \
1717
--pretrained_model_path ${WEIGHTS}

Diff for: monoforce/src/monoforce/datasets/rough.py

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def get_traj(self, i, T_horizon=None):
238238
# repeat the last pose to fill the trajectory
239239
poses = np.concatenate([poses, np.tile(poses[-1:], (n_frames - len(poses), 1, 1))], axis=0)
240240
stamps = np.concatenate([stamps, stamps[-1] + np.arange(1, n_frames - len(stamps) + 1) * dt], axis=0)
241+
assert len(poses) == n_frames, f'Poses and stamps have different lengths {len(poses)} != {n_frames}'
241242
# truncate the trajectory
242243
poses = poses[:n_frames]
243244
stamps = stamps[:n_frames]

Diff for: monoforce/src/monoforce/losses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def hm_loss(height_pred, height_gt, weights=None, h_max=None):
9999
return loss
100100

101101

102-
def physics_loss(states_pred, states_gt, pred_ts, gt_ts, gamma=0., rotation_loss=False):
102+
def physics_loss(states_pred, states_gt, pred_ts, gt_ts, gamma=0.9, rotation_loss=False):
103103
"""
104104
Compute the physics loss between predicted and ground truth states.
105105
:param states_pred: predicted states [N x T1 x 3]

Diff for: monoforce/src/monoforce/models/dphysics.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,17 @@ def forward_kinematics(self, t, state):
170170
assert in_contact.shape == (B, n_pts, 1)
171171

172172
# reaction at the contact points as spring-damper forces
173+
m, g = self.dphys_cfg.robot_mass, self.dphys_cfg.gravity
173174
xd_points_n = (xd_points * n).sum(dim=2).unsqueeze(2) # normal velocity
174175
assert xd_points_n.shape == (B, n_pts, 1)
175176
F_spring = -torch.mul((stiffness_points * dh_points + damping_points * xd_points_n), n) # F_s = -k * dh - b * v_n
176177
F_spring = torch.mul(F_spring, in_contact) / n_pts # apply forces only at the contact points
178+
F_spring = torch.clamp(F_spring, min=-m*g, max=m*g)
177179
assert F_spring.shape == (B, n_pts, 3)
178180

179181
# static and dynamic friction forces: https://en.wikipedia.org/wiki/Friction
180182
thrust_dir = normalized(R[..., 0]) # direction of the thrust
181183
N = torch.norm(F_spring, dim=2) # normal force magnitude at the contact points
182-
m, g = self.dphys_cfg.robot_mass, self.dphys_cfg.gravity
183184
track_vels = vw_to_track_vels(v=controls_t[:, 0], w=controls_t[:, 1],
184185
robot_size=self.dphys_cfg.robot_size, n_tracks=len(self.dphys_cfg.driving_parts))
185186
assert track_vels.shape == (B, len(self.dphys_cfg.driving_parts))
@@ -195,6 +196,7 @@ def forward_kinematics(self, t, state):
195196
vels_diff_tau = vels_diff - vels_diff_n * n # tangential velocity difference
196197
F_friction = N.unsqueeze(2) * vels_diff_tau # F_f = mu * N * v
197198
# F_friction = N.unsqueeze(2) * vels_diff
199+
F_friction = torch.clamp(F_friction, min=-m*g, max=m*g)
198200
assert F_friction.shape == (B, n_pts, 3)
199201

200202
# rigid body rotation: M = sum(r_i x F_i)

0 commit comments

Comments
 (0)