PDA

View Full Version : Complicated but interesting.....Need some thoughts



Megahertz
- 3rd July 2012, 12:12
I am using 16F877A for this work.
I had done a chart with 2 values before but I can't stop thinking about how to do it with 3 values. I have attached a pdf of a chart which I would like to load it in PIC. Based on the extension, I can calculate the Radius, then I need to pick the weight.

With the 2 values whichI did before, I used PokeCode and stored around 500 values as a table in my PIC. But my thought process has stopped working with this one, so can any one put their thoughts forward on how you see it getting done. Thanks

Megahertz
- 3rd July 2012, 22:44
Is it really that complicated as I think it is. May be C is better for this kind of task. Has anyone dealt with charts like this one?
Once I increase the resolution of radius to 0.1 increments and extension to also 0.1 increments I will get a lot of values for the table. Even if I think of saving values of weight for every row of radius in 0.1 increments, my table could easily run into 100's of values or could be 1000's for bigger tables than the attached one. I believe there has to be a different way of dealing with tables like this one.
.
.
.
.
.Anyone?

:rolleyes:

ScaleRobotics
- 4th July 2012, 07:33
Hi Megahertz,

The first question sounded pretty easy, with a 4 x 4 chart. Could do that using separate case statements, though not elegant. But you made it a lot tougher with .1 increments :) in the second question.

Darrel showed how to use 2d arrays here: http://www.picbasic.co.uk/forum/showthread.php?t=12870
But how are you going to populate all the data points? Do you have the formulas for the load charts of the cranes?

rsocor01
- 4th July 2012, 07:33
Megahertz,

I'm not sure I fully understand what you are trying to do, but there is a trick to store a 3-dimensional funtion in arrays. In other words, having an array with two variables in PBP. For example, taking data from your table,



Radius var byte
Extension var byte
Weight var byte[100]

Radius = 2
Extension = 5
Weight[(10 * Radius) + Extension] = 11 'Assuming Extension < 10

To make it work with decimals you might need to multiply those numbers by 10. Again, I'm not sure if what you want to do is something like this.

Robert

Megahertz
- 4th July 2012, 12:11
To explain my problem in detail, here is the actual chart. Now I have 3 more charts like this as every chart belongs to one hook of the crane and there are 4 hooks in total. 6565

As you can see above the radius ranges from 2 to 16. I have break it down to 0.1 increments for the sake of accuracy. So when I reach from 2 to 3, I already will have 10 values, then another 10 and in total around 140 values. Similar concept goes for the Boom length in meters @ 0.1 increments.

Now I can get the reading of boom length and I can get my Radius value. Now based on these two values, I need to pick the value of the weight from this chart.

Since I will have so many values, I am even doubting now if I can actually do it using an 877. I will go through your answers in detail later and see if it will be possible. Thanks for the replies.

Megahertz
- 4th July 2012, 12:37
Do you have the formulas for the load charts of the cranes?

No, don't have formula for the weight. I will have to load the values myself into the memory.

ScaleRobotics
- 4th July 2012, 14:56
Here's one way to do it.

You could have 5 lookup tables. One for each boom length. Say the boom is between 10 and 12 meters extended, so in between the values of your chart... For example the boom is at 10.5 meters, and radius is 5 meters. Do the lookup for the nearest known values, so lookup for the 10 meter, and the lookup for the 12 meter boom extension.

4760 at 10 meter extension
4000 at 12 meter extension

Difference between the two extensions is 12 - 10 = 2 meters. We are at .5 meters over 10, so 1/4 the difference. The difference in load is 760 for the two lengths. So 1/4 of 760 = 190.

4760 - 190 = 4570

load at 10.5 meter boom extension, at 5 meter radius = 4570

If you had a radius that was in between two numbers on the load chart, you could do similar lookups on the two radius's which the actual radius is between. Then do similar math.

rsocor01
- 4th July 2012, 19:41
How accurate do you need the data to be? From your table for each column you can approximate and find a formula. The results can be very close to what you have. The formulas are very easy to get using Excel.

Robert

Megahertz
- 4th July 2012, 21:46
Thanks for the replies.

Scalerobotics, could you explain with a little code snippet for my better understanding please.

Robert, I want them to be as accurate as practically possible. Of course I understand there is always a slight margin of error but lets see how this one goes. I knew that you can put formulas in Excel and get values but didn't knew that by putting values one can come up with formulas as well, so could you please explain more how to do it.

rsocor01
- 5th July 2012, 00:45
Robert, I want them to be as accurate as practically possible. Of course I understand there is always a slight margin of error but lets see how this one goes. I knew that you can put formulas in Excel and get values but didn't knew that by putting values one can come up with formulas as well, so could you please explain more how to do it.


Very easy :). Using data from your table and the column for Length = 13.85m,


6567

First, plot the data as a X-Y graph. Then goto Charts -> Add Trendline. I chose a second degree polynomial for the approximation since it's clearly not a stright line. R^2=0.9993 refers to how close to been perfect is the line fitting approximation (R^2=1 is perfect).

Robert

Megahertz
- 5th July 2012, 22:10
I will work with what I have got. Will report back very soon. Thanks for the help

Megahertz
- 6th July 2012, 18:08
ScaleRobotics, please could you help me get started with the coding side, I want to try your approach as well and see how it goes but though I understand what you meant above but I need help as to how I should approach it from the coding point of view. Thanks

ScaleRobotics
- 6th July 2012, 18:46
Hi Megahertz,

As I understand it, you are going to have an boom length variable that will probably be in between two numbers on the boom chart. And you will also have a radius variable that will be between two of the numbers on the boom chart.

The excel example is a bit cleaner (ok, alot cleaner), but you will still have to do an average between two (of the of 5 separate equations for weight at given boom length) since your radius isn't likely to lie right on a radius in the table.

One way to do this, would be to have a lookup table for each boom length listed on the chart. You would perform a lookup on the two tables (one above and one below) your actual boom length. You would give those an average, based upon what the value on the boom length was, as shown in the earlier example. First this would be done for a radius on the chart that was below your actual radius, then you would perform this below your actual radius. Then, as in the averaging example, you would average for the results at the two radius's depending on how close your actual radius was to the chart.

Using the excel equations, you only have to do one of these creative averaging. Using the lookup, you would have to do two creative averaging.

I started trying to show an example, but pretty much I think I would have to write the whole thing out. And I leave on a internet free vacation in about 30 minutes :)

Ok, here are a few raw uncomplete thoughts. No where near complete, but might give you an idea:





Weight var word 'capacity at given radius
Weight1 var word 'Low capacity at higher boom length
Weight2 var word 'high capacity at lower boom length
Weight3 var word 'Low capacity at high boom (at next closest radius)
weight4 var word 'high capacity at lower boom length (at next closest radius)
weightDiff1 var word 'weight difference between nearest values Weight1 & 2
weightDiff2 var word 'weight difference between nearest values Weight3 & 4
radiusLook var byte 'lookup radius value = (radius/100) -1
'radius var word 'radius in centimeters: 100 = 10 meters
remainder var byte
'boomLength var word ' boom length in centimeters 593 = 5.93 meters
radiusLeftover var byte ' remainder radius from division
radius con 50 'set radius to 5.0 meters
boomLength con 1050 ' set boom length to 10.5 meters


Main:


radiusLook = radius/10 - 2 'sets up our lookup table value 0 starting at 2
radiusLeftover = radius//10
gosub lookThemUp
weight3 = weight1
weight4 = weight2
radiusLook = radiuslook + 1 'next highest radius and put values into weight1 & 2
gosub logthemup
weightdiff1 = weight1 - weight2
weightdiff1 = weight3 - weight4
radiusleftover * weightdiff1



end
'************************************************
lookThemUp:
select case boomLength
case boomLength > 1293 and boomlength < 1386 'halfway between 13.85 and 12.00
'and all the way up to max radius without manual extension ...
'probably need another lookup table exclusively for the extension
gosub lookup_col5 'get weight value from column 5 of the table
weight1 = weight
gosub lookup_col4 'get weight value from column 4 of the table
weight2 = weight

case boomlength > 1100
gosub lookup_col4
weight1 = weight
gosub lookup_col3
weight2 = weight

case boomlength > 900
gosub lookup_col3
weight1 = weight
gosub lookup_col2
weight2 = weight

case boomlength > 593
gosub lookup_col2
weight1 = weight
gosub lookup_col1
weight2 = weight

end select
return


lookup_col1:
'radius = 5.93
lookup2 radiusLook,[7500,7500,5750,0,0,0,0,0,0,0,0,0,0],Weight
return

lookup_col2:
'radius = 8
lookup2 radiusLook,[7500,7500,5700,4400,3600,0,0,0,0,0,0,0,0],Weight
return

lookup_col3:
'radius = 10
lookup2 radiusLook,[7500,6900,5070,4760,3525,2900,2400,0,0,0,0,0,0],Weight
return

lookup_col4:
'radius = 12
lookup2 radiusLook,[0,5200,4500,4000,3475,2900,2478,2130,0,0,0,0,0],Weight
return

lookup_col5:
'radius = 13.85
lookup2 radiusLook,[0,0,3970,3460,3100,2750,2400,2080,1775,1550,1350,0 ,0],Weight
return


Then need to go through again at

Megahertz
- 18th July 2012, 16:00
Hi, I have successively done the coding for the radius and boom. I am now onto picking up the weight on this combination. I require a little more explanation on the calculation above. What I have written as a start is the following, I know it needs more polishing, but some help towards it will really be appreciated.


' WRadius comes to this part of the code with radius in centimeters (200 to 1600)
' WBoom comes to this part of the code with boom length in centimeters
' bRad_Look have radius in Meter
' WSafe will preferably have the actual value of the weight in Kgs

Get_A:
If wBoom>550 & wBoom<800 then GoSub Col1A
If wBoom>=800 & wBoom<1000 then GoSub Col2A
If wBoom>=1000 & wBoom<1200 then GoSub Col3A
If wBoom>=1200 & wBoom<1385 then GoSub Col4A
If wBoom>=1385 &wBoom<1400 then GoSub Col5A
If wBoom>1400 then GoSub Col6A
Return

Col1A:
bRad_Look=wRadius/100
Lookup Rad_Look,[0,0,75,75,57],wSafe
wSafe=wSafe*100
If Rad_Look=4 then wSafe=wSafe+50
Return

Megahertz
- 18th July 2012, 19:27
Very easy :). Using data from your table and the column for Length = 13.85m,

First, plot the data as a X-Y graph. Then goto Charts -> Add Trendline. I chose a second degree polynomial for the approximation since it's clearly not a stright line. R^2=0.9993 refers to how close to been perfect is the line fitting approximation (R^2=1 is perfect).

Robert

Robert, I also tried your method and found formulas for all the columns. Now I am trying to implement them, and I am facing a problem with calculations. For example formula for my first column comes to be :



y = -875x^2 + 4375x + 2250
Rē = 1


Now my x is the radius. While calculating on excel sheet I just put 2,3,4 as radius values and their corresponding load in front. Now my actual radius is in centimeters. How do I calculate if I want for example 215 centimeters) OR (264 centimeters)? Should I make a new graph with radius in centimeters all the way from 200 to 400 or is there a better way to do it?

rsocor01
- 18th July 2012, 21:44
Hmm, just a quick look. You can use the same formulas. The "in-between" values will be found in the formula by interpolation. But, if you use cm you might need to declare your variables as LONG instead of WORD

Megahertz
- 22nd July 2012, 17:26
Thanks guys for your replies. It has surely helped me upto now and I have made the software reliable enough to pick the correct MAX safe weight from the chart. Without the above examples my task would have been much more harder. My next task is to monitor the radius and boom so that the ACTUAL lifted weight stays within the safe parameter. I would appreciate your thoughts on accomplishing this next next task. Please let me know if you need more explanation on this.

rsocor01
- 23rd July 2012, 03:53
Thanks guys for your replies. It has surely helped me upto now and I have made the software reliable enough to pick the correct MAX safe weight from the chart. Without the above examples my task would have been much more harder. My next task is to monitor the radius and boom so that the ACTUAL lifted weight stays within the safe parameter. I would appreciate your thoughts on accomplishing this next next task. Please let me know if you need more explanation on this.

Well, If I underestand your question correctly, then just some more code like this would do the job.


IF (Radius < Radius_Min) or (Radius > Radius_Max) then DoSomething
IF (Boom < Boom_Min) or (Boom > Boom_Max) then DoSomethingElse

Megahertz
- 25th July 2012, 11:05
Robert Thanks, but I do not see this to be this easy because once the radius and boom will change the weight could change drastically from one column to another in some cases. So something which kind of predicts 3-4 steps ahead of the limit being reaching would work better, but can't imagine clearly on how to start something like that.

Megahertz
- 28th August 2012, 17:48
Here's one way to do it.
4760 at 10 meter extension
4000 at 12 meter extension

Difference between the two extensions is 12 - 10 = 2 meters. We are at .5 meters over 10, so 1/4 the difference. The difference in load is 760 for the two lengths. So 1/4 of 760 = 190.

4760 - 190 = 4570

load at 10.5 meter boom extension, at 5 meter radius = 4570


It has been some time with this project and I have been able to reach to some solid ground in picking up weights using the correct radius using graphs. The two weights I get are correct. I am a little stuck with the calculation as you advised above for averaging. I have written a routine to do the calculations between the two weights as above but I am not sure if it is entirely correct as the results are not satisfactory:

If (wWeight1>wWeight2) then
wTemp=((wBoomDiff*100)/bBoom_Jump) ; Boom Diff can be from 1 to 206. Boom jump can only be 200 or 185 or 207
wDummy=wTemp * (wWeight1-wWeight2) ; Bit confused as this can result in 32 bit result or not, so not sure how to implement DIV32 here
wSafe=wWeight1-wDummy
Else
If (wWeight2>wWeight1) then ; Same confusion as above
wTemp=((wBoomDiff*100)/bBoom_Jump)
wDummy=wTemp * (wWeight2-wWeight1)
wSafe=wWeight1 +wDummy
Else
wSafe=wWeight1
Endif
Endif