Skip to content
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

Open
slemvs opened this issue Sep 11, 2021 · 4 comments
Open

Change maxheight of the vehicle in runtime for lua profile #343

slemvs opened this issue Sep 11, 2021 · 4 comments

Comments

@slemvs
Copy link

slemvs commented Sep 11, 2021

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?

@TomQv
Copy link

TomQv commented May 10, 2022

Good question, would also like to know

@slemvs
Copy link
Author

slemvs commented May 10, 2022

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.

@TomQv
Copy link

TomQv commented May 10, 2022

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.
For example, I would also need an "avoid highways" option, selectable at runtime.

@slemvs
Copy link
Author

slemvs commented May 11, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants