Compare commits
2
Commits
190a8ad334
...
8680cdbee7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8680cdbee7 | ||
|
|
f65eb98d18 |
No files matched your search
@@ -186,7 +186,9 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
|
||||
*** [x] The compass (HMC5883L on node 0x21, TPDO 0x221) as `imu.heading` + `mag.x/y/z` in
|
||||
`can.json` — for orienting while standing; driving uses the GNSS course
|
||||
*** [ ] Tilt compensation (pitch/roll from the IMU) and hard-/soft-iron calibration of the
|
||||
heading — ESPHome's is a plain `atan2(y, x)`; in the node, like the levelling
|
||||
heading — ESPHome's is a plain `atan2(-x, y)`; in the node, like the levelling
|
||||
*** [x] The node sent the heading encoded 0..360 but ESPHome's is −180..180, negatives arrived
|
||||
as 0 — fixed in the node (`x < 0 ? x + 360 : x` filter on `heading:`, 2026-11-30)
|
||||
*** [ ] IMU every 100–200 ms (the node reads it every 5 s today) and levelling done by the
|
||||
node itself, set by an SDO write from a button in `/can.html` — design in home-gitops
|
||||
`docs/canopen-nodes.adoc` ("Nulovanie náklonu a rýchlosť IMU")
|
||||
|
||||
@@ -384,6 +384,31 @@ module Maptool
|
||||
|
||||
GNSS_LATEST = {}
|
||||
GNSS_LATEST_MUTEX = Mutex.new
|
||||
COURSE_MIN_M = 5 # fixes closer than this: too noisy for a course
|
||||
COURSE_MIN_SPEED = 1.5 # m/s: slower, the last course stays
|
||||
|
||||
# Where every GNSS fix lands (the node over CAN, the simulation): into
|
||||
# GNSS_LATEST, with the course over ground (track, °) worked out from
|
||||
# the fix COURSE_MIN_M back when the receiver sends none — following
|
||||
# heading-up from behind (followPosition, gnss.js) turns by it.
|
||||
def self.gnss_update(gnss, at: Time.now.to_f)
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
GNSS_LATEST.merge!(gnss)
|
||||
next unless gnss.key?(:lat) || gnss.key?(:lon)
|
||||
|
||||
GNSS_LATEST[:received_at] = at
|
||||
next if gnss.key?(:track)
|
||||
|
||||
position = GNSS_LATEST.values_at(:lon, :lat)
|
||||
from = GNSS_LATEST[:course_from]
|
||||
if from.nil? || (GNSS_LATEST[:speed] || 0) < COURSE_MIN_SPEED
|
||||
GNSS_LATEST[:course_from] = position
|
||||
elsif GnssSim.meters(from, position) >= COURSE_MIN_M
|
||||
GNSS_LATEST[:track] = GnssSim.bearing(from, position).round(1)
|
||||
GNSS_LATEST[:course_from] = position
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Native CAN (lib/maptool/can.rb), on when data/can.json exists: one
|
||||
# reader thread per interface. Signals named gnss.<field> (lat, lon,
|
||||
@@ -410,10 +435,7 @@ module Maptool
|
||||
gnss = values.filter_map { |name, value| [name.delete_prefix("gnss.").to_sym, value] if name.start_with?("gnss.") }.to_h
|
||||
next if gnss.empty? || GNSS_SIM.running?
|
||||
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
GNSS_LATEST.merge!(gnss)
|
||||
GNSS_LATEST[:received_at] = Time.now.to_f if gnss.key?(:lat) || gnss.key?(:lon)
|
||||
end
|
||||
App.gnss_update(gnss)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1251,7 +1273,7 @@ module Maptool
|
||||
CAN_STORE.override_prefix = "gnss."
|
||||
GNSS_SIM.start(lon, lat) do |fix|
|
||||
CAN_STORE.put(fix.transform_keys { |key| "gnss.#{key}" })
|
||||
GNSS_LATEST_MUTEX.synchronize { GNSS_LATEST.merge!(fix, received_at: Time.now.to_f) }
|
||||
App.gnss_update(fix)
|
||||
end
|
||||
json running: true
|
||||
rescue JSON::ParserError
|
||||
@@ -1281,7 +1303,7 @@ module Maptool
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
received_at = GNSS_LATEST[:received_at]
|
||||
fresh = received_at && (Time.now.to_f - received_at) < GNSS_STALE_AFTER
|
||||
json(fresh ? GNSS_LATEST.merge(available: true) : { available: false })
|
||||
json(fresh ? GNSS_LATEST.except(:course_from).merge(available: true) : { available: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+11
-2
@@ -253,10 +253,19 @@ same node) isn't in the firmware yet:
|
||||
|
||||
Speed's scale also converts km/h to m/s (`300 / 65534 / 3.6`). 0x221 is
|
||||
the HMC5883L (TPDO 4 → `0x200 + node`): the field ±200 µT and ESPHome's
|
||||
heading 0..360°, plain `atan2(y, x)` — no tilt compensation or hard-iron
|
||||
calibration yet, so only roughly right standing level. The node
|
||||
heading 0..360° (ESPHome's plain `atan2(-x, y)` is −180..180, the node
|
||||
adds 360 to the negatives — a filter on `heading:`). No tilt compensation
|
||||
or hard-iron calibration yet, so only roughly right standing level. The node
|
||||
goes operational by itself, so no `nmt_start`.
|
||||
|
||||
The node sends no course: `App.gnss_update` (where every fix lands, the
|
||||
node's and the GNSS simulation's) works it out from the fix ≥ 5 m back
|
||||
while moving ≥ 1.5 m/s and keeps the last one standing still, so
|
||||
`/api/gnss/position` has `track` and following in 3D turns heading-up.
|
||||
The simulation (Dashboard settings, `POST`/`DELETE /api/sim/gnss`) drives
|
||||
random trips over the local Valhalla and stands in for the node's `gnss.*`
|
||||
meanwhile — on the car's server only for trying things out.
|
||||
|
||||
=== Map data (one way)
|
||||
|
||||
`bin/pull-maps.sh`, run by `maptool-pull-maps.timer` (10 min after boot,
|
||||
|
||||
@@ -93,6 +93,15 @@ module Maptool
|
||||
raise Routing::RouteError, "no route from #{position.map { |v| v.round(5) }.join(', ')}: #{last&.message}"
|
||||
end
|
||||
|
||||
# Initial bearing from one [lon, lat] to another, 0..360° from north.
|
||||
def self.bearing((lon1, lat1), (lon2, lat2))
|
||||
rad = Math::PI / 180
|
||||
d = (lon2 - lon1) * rad
|
||||
y = Math.sin(d) * Math.cos(lat2 * rad)
|
||||
x = Math.cos(lat1 * rad) * Math.sin(lat2 * rad) - Math.sin(lat1 * rad) * Math.cos(lat2 * rad) * Math.cos(d)
|
||||
(Math.atan2(y, x) / rad) % 360
|
||||
end
|
||||
|
||||
def self.meters((lon1, lat1), (lon2, lat2))
|
||||
Math.hypot((lon2 - lon1) * Math.cos((lat1 + lat2) / 2 * Math::PI / 180), lat2 - lat1) * 111_320
|
||||
end
|
||||
|
||||
@@ -662,6 +662,23 @@ class AppTest < Minitest::Test
|
||||
assert_equal 404, response.status
|
||||
end
|
||||
|
||||
def test_a_gnss_fix_without_a_course_gets_one_from_the_fixes_before
|
||||
latest = Maptool::App::GNSS_LATEST
|
||||
latest.clear
|
||||
step = 10.0 / 111_320 # 10 m north each fix
|
||||
Maptool::App.gnss_update({ lat: 48.0, lon: 17.0, speed: 10.0 })
|
||||
assert_nil latest[:track]
|
||||
Maptool::App.gnss_update({ lat: 48.0 + step, lon: 17.0 })
|
||||
assert_in_delta 0.0, latest[:track], 0.1
|
||||
Maptool::App.gnss_update({ lat: 48.0 + step, lon: 17.0 + step / Math.cos(48 * Math::PI / 180) })
|
||||
assert_in_delta 90.0, latest[:track], 0.5
|
||||
Maptool::App.gnss_update({ speed: 0.0 })
|
||||
Maptool::App.gnss_update({ lat: 48.0, lon: 17.0 }) # standing still: the course stays
|
||||
assert_in_delta 90.0, latest[:track], 0.5
|
||||
ensure
|
||||
latest.clear
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def upload(filename, content, folder: "", content_type: "application/octet-stream")
|
||||
|
||||
Reference in new issue
Block a user