I am modeling a simulation of an APM (Automated Power Management) system where the machine adjusts its gear and RPM to react to a variable workload. I am modeling it off a tractor. So, for this model the variable workload would be increasing/decreasing resistance force the tractor has to pull.
I am stuck with the gearbox. I have the code determining wheel torque required, and I need to do an inverse table lookup. The table is set up like f(x,y)=z where x=Throttle Position/RPM, y=Gear and z=Wheel Torque. In this instance I know my throttle position, and I know torque required, I need a way for it to give me the corresponding gear.
Here's what the table looks like:
I know how to use the 2-D table look up to find z from x and y, but not to find y with x and z.
I've created an example using the top-left corner of your provided map
Click the image to see the full resolution version...
I've added displays in yellow so you can see the input map, as well as various values through the model. The input map values I've used are a subset of your example data.
You can use a "Prelookup" block for your given RPM (e.g. 1000RPM) to determine the index (zero-based) and fraction (towards the following index) along the RPM axis.
You can spoof the pre-lookup for the 2nd axis because we want all values across the gears. To get all indicies we can use 0:(N-1)
for N
gears, with a fraction [0,0,...,0,1]
of the same length (note the final value only is a 1).
Feeding this and the table data for torque into an "Interpolation Using Prelookup" block, we can get the entire torque map (interpolated) at the current RPM vs gear.
We can now do a 1D lookup of gear number vs torque, which can be done using a "1-D Lookup Table" block. Note that the axis for this block must be monotonically increasing. Your torque map is monotonically decreasing as the gears increase, so we can flip both inputs using a "Selector" block set to indicies N:-1:1
for N
gears. You're fortunate here, if your map wasn't monotonically decreasing then this step would be more complicated, because there would be multiple possible gears for your desired torque.
I've set the 1-D interp block to "nearest" so you get the closest integer gear choice for your target torque. You could use linear interpolation here if you actually need to know how close to the next gear you are for anything downstream.
The main setting I had to change internally for any of the blocks was to set all "source" options for the interpolation blocks to "Input Port" so the data could be specified by the inputs on the left, rather than internal to the block dialog.