Skip to content

Commit 0e0435f

Browse files
authored
Merge pull request #10 from dfeen87/copilot/fix-code-bugs
Fix velocity validation logic and chrono API misuse
2 parents aafcec3 + 2f60926 commit 0e0435f

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build directories
2+
build/
3+
dist/
4+
_codeql_build_dir/
5+
*.o
6+
*.a
7+
*.so
8+
*.dylib
9+
*.exe
10+
11+
# CodeQL
12+
_codeql_detected_source_root
13+
14+
# IDE
15+
.vscode/
16+
.idea/
17+
*.swp
18+
*.swo
19+
*~
20+
21+
# Coverage
22+
*.gcda
23+
*.gcno
24+
*.gcov
25+
coverage/
26+
27+
# Temporary files
28+
/tmp/
29+
*.tmp

examples/hil/hil_rig_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static constexpr size_t MAX_LINE = 1024 * 1024;
4242

4343
uint32_t now_ms() {
4444
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
45-
std::chrono::steady_clock::now().time_since_epoch()
45+
std::chrono::system_clock::now().time_since_epoch()
4646
).count();
4747
return static_cast<uint32_t>(ms);
4848
}

include/PropulsionPhysicsEngine.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class PropulsionPhysicsEngine {
1010
static constexpr float MAX_THRUST_kN = 2500.0f;
1111
static constexpr float MIN_MASS_KG = 100.0f;
1212
static constexpr float MIN_VELOCITY_M_S = -20000.0f;
13+
static constexpr float MAX_VELOCITY_M_S = 20000.0f; // ~72,000 km/h
1314
static constexpr uint32_t PHYSICS_DT_MS = 10;
1415

1516
void init();

src/physics/propulsion_physics_engine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ bool PropulsionPhysicsEngine::is_state_physically_plausible(
169169
if (radius_sq < min_radius * min_radius)
170170
return false;
171171

172-
// Velocity sanity check
173-
if (state.velocity_m_s[0] < MIN_VELOCITY_M_S ||
174-
state.velocity_m_s[1] < MIN_VELOCITY_M_S ||
175-
state.velocity_m_s[2] < MIN_VELOCITY_M_S)
172+
// Velocity sanity check (magnitude per component)
173+
if (std::abs(state.velocity_m_s[0]) > MAX_VELOCITY_M_S ||
174+
std::abs(state.velocity_m_s[1]) > MAX_VELOCITY_M_S ||
175+
std::abs(state.velocity_m_s[2]) > MAX_VELOCITY_M_S)
176176
return false;
177177

178178
return true;

0 commit comments

Comments
 (0)