-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change maxheight of the vehicle in runtime for lua profile #343
Comments
Good question, would also like to know |
If anybody interesting in this, I can set custom parameter of the car lua profile in runtime this way: define custom parameter "currentHeight" in lua profile like this -- car globals
name = "car"
vehicle_types = { "vehicle", "motor_vehicle", "motorcar" }
constraints = { "maxweight", "maxwidth", "maxheight" }
parameters = {
currentHeight = "2"
}
minspeed = 30
maxspeed = 200
... and then use this parameter in C# code like this: var vehicle = DynamicVehicle.Load(File.ReadAllText(@"k:\_osm\profiles\custom-car.lua"));
var parameters = vehicle.Script.Globals.Pairs.FirstOrDefault(x => x.Key.String == "parameters");
parameters.Value.Table["currentHeight"] = req.VehicleHeight.ToString(CultureInfo.InvariantCulture);
var targetProfile = vehicle.Fastest(); In runtime i see that new value for this parameter was set, but i dont know how to avoid edge in factor_and_speed function using this custom vehicle height. |
I also don't know. From what I remember, @xivk said a while (some years) ago, with contracted routerdbs its not possible to change anything at runtime. |
In lua profile, in factor_and_speed function i can get dynamic value of the parameter: local canAccess = true;
if attributes.maxheight then
local height = itinero.parsespeed(attributes.maxheight)
local height2 = itinero.parsespeed(parameters.currentHeight)
itinero.log('height: ' .. tostring(height) .. ' - ' .. tostring(height2))
if height < height2 then
canAccess = false;
end
end
if canAccess == false then
result.speed = 0
result.direction = 0
result.canstop = true
return
end in console i can see new value of the currentHeight (height2) parameter, but router builds route ignoring this code. In app i set custom vehicle height to 6.5m, and then, when i build route with router i can see this data in console: [RouterBaseExtensions] information - Profile(s) car not cached, building cache.
[Lua] information - height: 3.5 - 6.5
[Lua] information - height: 3.5 - 6.5
[Lua] information - height: 2.5 - 6.5
[Lua] information - height: 3 - 6.5
[Lua] information - height: 4 - 6.5
[Lua] information - height: 2 - 6.5
[Lua] information - height: 4.800000190734863 - 6.5
[Lua] information - height: 3.299999952316284 - 6.5
[Lua] information - height: 3.5 - 6.5
[Lua] information - height: 2.0999999046325684 - 6.5
[Lua] information - height: 3.5 - 6.5
[Lua] information - height: 3.5 - 6.5
these logs from line in lua profile itinero.log('height: ' .. tostring(height) .. ' - ' .. tostring(height2)) routerdb file was created with custom lua profile in this case |
Hi @xivk and all itinero team, thank you for great and very usefull library.
In my application user can add to own profile several vehicles, for example, several small trucks with different heights: 3m and 4m. Can we use for this case one lua profile, save contracted db with this lua profile and use it later with 2 different vehicles with different heights?
Can we set height of the vehicle in runtime (not hardcoded constant in lua, but any variable that we could check)?
Is there any "constraints" of the vehicle from C# code available in lua?
The text was updated successfully, but these errors were encountered: