Archive

Archive for the ‘KnowWhat’ Category

kDevelop 4.2 Debugging

November 7th, 2011 No comments
    When I was using KDevelop 4.2 for debugging a process, I got perplexed having the inferior application closing down whenever I was setting a breakpoint on the fly.  On the contrary, the breakpoints there were setup before the start of the inferior application, things behave as expected.  With little bit of digging, it is found that whenever a new breakpoint is setup or removed (Toggle Breakpoint), kDevelop inherently issues a SIGINT to the inferior application, which in turn stops the application from debugging.  To handle this problem, setup a signal handler for SIGINT, to consume the Interrupt signal (Ctrl+C, Ctrl+Break).  But once the debugging is over, don’t forget to reset the SIGINT handler.

Hash Overflow due to 64 bit upcasting

October 28th, 2011 No comments
    Lately, I had to debug the following piece of code, where it caused overflow on the hash bucket design.  The code worked perfectly on a Windows machine while compiled for Win32, but failed to work on a Linux Mint x64 machine.  The code is listed below, which basically calculates hash value of an input 32 bit unsigned number, limiting the hash value to 2^10 (1Meg).

hash = ( fpArray*2654404609 )>>12; // Calculate the hash and limit the value to 2^20 (1 Meg)

   When the input value for fpArray was 1724463449 (0x66C93959), the hash value generated was 1779068547 (0x6A0A6E83), which is more than (0x000FFFFF) to cause the hash bucket overflow.

unsigned hash = fpArray * 2654404609;
hash = hash >> 12;

    When I rewrote the code like the above, the value of hash was 2800236889 (0xA6E83959).  Upon shifting right by 12 yields 638651 (0x0009BEBB), which is the correct and expected hash value.

    Overall, the first snippet of code appears to be correct.  Do you see a problem there?  I couldn’t find the issue, until I recalled the 32bit vs 64bit difference.  If you carefully look at the multiplier 2654404609 (0x9E370001), although appears to be a valid 32 bit number, what is the default assignment of type to this number by the compiler?  If it was assigned 64bits, what would happen to the results?  To validate this, I changed the 2nd snippet as the following.

unsigned long hash = (unsigned long)fpArray * 2654404609;
hash = hash >> 12;
unsigned h2 = (unsigned)hash;

    Now, when the input is the same 1724463449 (0x66C93959), the value of hash becomes 4577423727077636441 (0x3F8646A0A6E83959) and upon right shifting by 12 bits yields 1117535089618563 (0x0003F8646A0A6E83). Followed by downcasting to unsigned yield 1779068547 (0x6A0A6E83). Bingo!

    So, what is happening here? While performing (fpArray * 2654404609), the computation is upcasted to 64bit computation by the 64 bit compiler.  So, what is the solution? Just put a “U” at the end of the constant.

hash = ( fpArray*2654404609U )>>12; // Calculate the hash and limit the value to 2^20 (1 Meg)
(or)
const unsigned multipler = 2654404609; // here U suffix is not needed as the constant is explicitly made unsigned
hash = ( fpArray * multiplier ) >> 12;

    Now, the computation will happen with 32 bit numbers to get the expected outputs.

Lessons Learned here:

  1. While using constants, beware of the upcasting and downcasting. So use proper suffixes like U, L, F etc.
  2. Instead of using constants directly in expressions, use them as constant variables.
  3. Be conscious about the compiler type and the assumptions made by the compiler in different build modes.

AWG Vs Current Flow Capacity

September 13th, 2011 No comments

This write up is taken from http://www.engineeringtoolbox.com/wire-gauges-d_419.html

The AWG – American Wire Gauge – is used as a standard method of denoting wire diameter, measuring the diameter of the conductor (the bare wire) with the insulation removed. AWG is sometimes also known as Brown and Sharpe (B&S) Wire Gauge.

The AWG table below is for a single, solid, round conductor. Because of the small gaps between the strands in a stranded wire, a stranded wire with the same current-carrying capacity and electrical resistance as a solid wire, always have a slightly larger overall diameter. The higher the number – the thinner the wire. Typical household wiring is AWG number 12 or 14. For telephone wires there are common with AWG 22, 24, or 26.

AWG Diameter
(mm)
Diameter
(in)
Square
(mm2)
Resistance
(ohm/1000m)
40 0.08 . 0.0050 3420
39 0.09 . 0.0064 2700
38 0.10 0.0040 0.0078 2190
37 0.11 0.0045 0.0095 1810
36 0.13 0.005 0.013 1300
35 0.14 0.0056 0.015 1120
34 0.16 0.0063 0.020 844
33 0.18 0.0071 0.026 676
32 0.20 0.008 0.031 547
30 0.25 0.01 0.049 351
28 0.33 0.013 0.08 232.0
27 0.36 0.018 0.096 178
26 0.41 0.016 0.13 137
25 0.45 0.018 0.16 108
24 0.51 0.02 0.20 87.5
22 0.64 0.025 0.33 51.7
20 0.81 0.032 0.50 34.1
18 1.02 0.04 0.82 21.9
16 1.29 0.051 1.3 13.0
14 1.63 0.064 2.0 8.54
13 1.80 0.072 2.6 6.76
12 2.05 0.081 3.3 5.4
10 2.59 0.10 5.26 3.4
8 3.25 0.13 8.30 2.2
6 4.115 0.17 13.30 1.5
4 5.189 0.20 21.15 0.8
2 6.543 0.26 33.62 0.5
1 7.348 0.29 42.41 0.4
0 8.252 0.33 53.49 0.31
00 (2/0) 9.266 0.37 67.43 0.25
000 (3/0) 10.40 0.41 85.01 0.2
0000 (4/0) 11.684 0.46 107.22 0.16

The higher the gauge number, the smaller the diameter, and the thinner the wire.  Because of less electrical resistance a thick wire will carry more current with less voltage drop than a thin wire. For a long distance it may be necessary to increase the wire diameter – reducing the gauge – to limit the voltage drop.

American Wire Gauge (AWG)
Length
(feet)
Current (amps)
5 10 15 20 25 30 40 50 60 70
15 16 12 10 10 8 8 6 6 4 4
20 14 12 10 8 8 6 6 4 4 4
25 14 10 8 8 6 6 4 4 2 2
30 12 10 8 6 6 4 4 2 2 2
40 12 8 6 6 4 4 2 2 1 1/0
50 10 8 6 4 4 2 2 1 1/0 1/0
60 10 6 6 4 2 2 1 1/0 2/0 2/0
70 10 6 4 2 2 2 1/0 2/0 2/0 3/0
80 8 6 4 2 2 1 1/0 2/0 3/0 3/0
90 8 4 4 2 1 1/0 2/0 3/0 3/0 4/0
Standard Wire Gauge (SWG)

SWG inches mm
7/0 0.500 12.700
6/0 0.464 11.786
5/0 0.432 10.973
4/0 0.400 10.160
3/0 0.372 9.449
2/0 0.348 8.839
1/0 0.324 8.236
1 0.300 7.620
2 0.276 7.010
3 0.252 6.401
4 0.232 5.893
5 0.212 5.385
6 0.192 4.877
7 0.176 4.470
8 0.160 4.064
9 0.144 3.658
10 0.128 3.251
11 0.116 2.946
12 0.104 2.642
13 0.092 2.337
14 0.080 2.032
15 0.072 1.829
16 0.064 1.626
17 0.056 1.422
18 0.048 1.219
19 0.040 1.016
20 0.036 0.914
21 0.032 0.813
22 0.028 0.711
23 0.024 0.610
24 0.022 0.559
25 0.020 0.508
26 0.018 0.457
27 0.0164 0.417
28 0.0148 0.376
29 0.0136 0.345
30 0.0124 0.315
31 0.0116 0.295
32 0.0108 0.274
33 0.0100 0.254
34 0.0092 0.234
35 0.0084 0.213
36 0.0076 0.193
37 0.0068 0.173
38 0.006 0.152
39 0.0052 0.132
40 0.0048 0.122
41 0.0044 0.112
42 0.004 0.102
43 0.0036 0.091
44 0.0032 0.081
45 0.0028 0.071
46 0.0024 0.061
47 0.002 0.051
48 0.0016 0.041
49 0.0012 0.030
50 0.001 0.025

Mother

July 31st, 2011 No comments

தாயின் பெருமைகளை என் தாய் எனக்குச் சொல்ல, இங்கே அதை தொகுத்துள்ளேன்.

  1. தாயில் சிறந்த கோவிலும் இல்லை
  2. தாயின் மடி மீண்டும் அமரமுடியாத சிம்மாசனம்
  3. குழந்தையின் எதிர்காலம் தாயின் கையில்தான் உள்ளது
  4. எல்லோரது இடத்தையும் தாய் வகிக்க முடியும், ஆனால் தாயின் இடத்தை வகிக்க வேறு எவராலும் முடியாது
  5. 1 கோடி போதனையை விட ஒருதுளி தாய்மை மேலானது
  6. மண்ணில் நல்லவனாக வாழவைப்பதும், நானிலத்தில் புகழ் பெற செய்வதும் தாய்தான்
  7. தாயை எதனோடும் ஒப்பிடுதல் கூடாது. ஏனெனில் அவள் ஈடுஇணை அற்றவள்
  8. உலகம் அனைத்தையும் ஒரு தட்டிலும், தாயை ஒரு தட்டிலும் வைத்து தராசில் நிறுத்தால் உலகின் தட்டுதான் மேலே இருக்கும்
  9. தாயின் இதயம்தான் குழந்தைகளின் பள்ளிக்கூடம்
  10. நல்ல தாயை அடைந்தவன் தான் சாதனைகளைப் படைத்து பெரிய மனிதனாக உருவெடுக்கிறான்
  11. தாயின் உள்ளத்தை அறிந்தவன் கடவுளின் கருணையை அறிந்தவன்
  12. வாஞ்சையுள்ள இதயதைப் பெற்றவளே தாயாவாள்
  13. தாயை வணங்குபவனுக்கு தெய்வம் வழிகாட்டும்
  14. தாய் எங்கிருக்கிறாளோ அந்த இடம் சொர்கம்
  15. தாயின் கண்ணீரை துடைப்பவனே சிறந்த மகன்
  16. அன்னைக்கு உதவாதவன் யாருக்கும் உதவாதவன்
  17. அன்னையின் அன்பிற்கு அளவில்லை
  18. தாயை பிரிந்த மகன் வெறும் கூடுதான்

Solar Panel Structure Design

July 17th, 2011 No comments

This was the original design of the solar panel mounting structure.  Later, I had simplified the design and fabricated them at the local metal fabricators.  Please click on the images to open the big sized drawing.

Pole that would hold the weight of a heavy solar panel over a base structure (not shown).

Hinge design that would transfer the weight from the base structure to the pole, with one degree of freedom.

சூரிய ஒளி மின்சாரம் (Solar Electricity)

July 10th, 2011 No comments

The completed Solar Panel mount structure.

Bottom side view of the panel.  The Panel is fully resting on the Iron frame constructed in the nearby fabrication shop based on my design.

This is my assistant Aakash, the boy next door.  He has been my aide for all the mechanical and automobile works.

The base frame of 30″ x 21″ with the center piece at 15″.

The base frame from perspective projection.  The center piece is a 5″ x 2″ 10mm plate welded at the center.  The holes are 10mm diameter drilled at 1″ and 3″ from the top and centered.

The main load bearing vertical pole measuring approx 2m and 2″ diameter.  The base plate is 6″ in horizontal length and 6″ on vertical depths.  The holes are 1/2″ and drilled at 3″ and 5″.

This is the solar panel bought from Akshaya Solar Pvt Ltd, AP.  The panel is rated 12v 70w and of dimension 1200mm x 21″ and weighting approximately 5kg.

The swing arm connecting the base frame and vertical pole.  The holes are 10 mm diameter and punched at 1″ and 3″ from the top.  The bottom pipe is 2.25″ diameter and about 5″ long.  The cross bolt is 0.5″ diameter.  This swing arm mounts on the pole on one side and attached to the base frame on the other side.  The base frame is pivoted on the top hole with swing setting using one of the 3 bottom holes.  The positions are provided to compensate of uttrayanam (north bound sun movement) and dakshanayanam (south bound sun’s movement).

The bottom link of the vertical pole.  This U link attaches to the parapet wall, which is 6″ is width and the cross bolts pass through the wall to lock the vertical plates.  The horizontal and the vertical plates are 6″x2″ and 10mm in thickness.

These are the bolts used.  The 1″ (4 nos) bolts are used to secure the solar panel on the base frame.  The 1.5″ bolts are used to secure the base frame to the swing arm.  The 4″ bolt is used to secure the swing arm to the vertical pole and the 8″ bolts are the bolts to secure the entire unit on the parapet wall by passing through the wall.

no include path in which to search for limits.h

June 16th, 2011 No comments

Why compiling STLport 5.1.5 using g++-4.4, one might get an error like the following:-

Building CXX object libs/bgt/CMakeFiles/bgt.dir/error.o
In file included from /opt/projects/stl/stlport/limits.h:27,
            from /usr/include/c++/4.4/../4.4.5/climits:43,
            from /opt/projects/stl/stlport/climits:27,
            from /opt/projects/stl/stlport/stl/_algobase.h:42,
            from /opt/projects/stl/stlport/stl/_alloc.h:47,
            from /opt/projects/stl/stlport/stl/_string.h:23,
            from /opt/projects/stl/stlport/stl/_ios_base.h:34,
            from /opt/projects/stl/stlport/stl/_ios.h:23,
            from /opt/projects/stl/stlport/stl/_ostream.h:24,
            from /opt/projects/stl/stlport/ostream:31,
            from /opt/projects/dev/libs/bgt/error.cpp:18:
/usr/include/../include/limits.h:125: error: no include path in which to search for limits.h
In file included from /opt/projects/stl/stlport/stl/_num_put.c:26,
            from /opt/projects/stl/stlport/stl/_num_put.h:183,
            from /opt/projects/stl/stlport/stl/_ostream.c:26,
            from /opt/projects/stl/stlport/stl/_ostream.h:380,
            from /opt/projects/stl/stlport/ostream:31,
            from /opt/projects/dev/libs/bgt/error.cpp:18:
/opt/projects/stl/stlport/stl/_limits.h:148: error: ‘CHAR_BIT’ was not declared in this scope
/opt/projects/stl/stlport/stl/_limits.h:253: error: ‘CHAR_MIN’ was not declared in this scope
..

Looks like it is a bug in the STLport package itself as per the Release notes of STLport.  After updating to STLport-5.2.1, the issue got fixed automatically.

Know to Say No

June 1st, 2011 No comments
மனிதன் தன்னுடைய கர்மத்தினால் ஏற்படுத்திக்கொள்ளக்கூடிய துயரத்தைவிட பிரதிகர்மத்தினாலேயே அதிக துயரை சம்பாதிக்கிறான். ஆங்கிலத்தில் ஒரு பழமொழி உண்டு, “You should know to say no”. அதாவது, இயலாது என்று சொல்லவேண்டிய இடத்தில் இயலாது என்றுரைக்க தெரிந்திருக்கவேண்டும். இதில் சிக்கல் என்னவென்றால், எங்கு இயலாது என்று கூறுவது, அதை எப்படிக்கூறுவது என்பதில் தான். அதில் தேர்ந்துவிட்டால், தேவைக்கு ஏற்ப வாழ்க்கையை அமைத்துகொள்வது எளிது.

“I am not obligated” என்று விட்டேத்தியாக இருந்துவிடுவது எளிது, ஆனால் இந்த குணத்தால் நண்பர்களை இழக்க நேரிடலாம். இருப்பினும், பொறுப்புகளுக்கும்(responsibilities) வேண்டுகோள்களை ஏற்பதற்கும்(being obligated) வேறுபாடு உண்டு என்பதை உணர்ந்து நடந்தால், திறமையாக நிலைமையை சமாளிக்கமுடியும் என்பதில் ஐயமில்லை.

Symmetric Sigmoid

May 14th, 2011 No comments
When unknown signed intervals are expected to be normalized to -1 to +1, a symmetric sigmoid function could prove very useful.  A Symmetric Sigmoid function is a modified version of the Sigmoid function by stretching it across the Y axis.  As per wikipedia, it is defined as a symmetric function is a special case of logistic function whose plot appears like a ‘S’ with the Y-axis intercept as 0.5 and min/max as 0/1 respectively.

The function definition for a sigmoid is:

In programming languages the implementation should be in order to overcome the numerical overflow and underflow issues:

if ( t < 0 )
    exp( t ) / ( 1.0 + ::exp( t ) )
else
    1.0 / ( 1.0 + ::exp( -t ) )

 

 

 

 

 

 

 

 

 

 

 

 

In the plot, if the curve is stretched in Y-axis to make the Y-intercept at 0.0, the lower bound would get stretched to -1.0.
The function definition for a symmetric sigmoid is:
P symmetric (t) = 2.0 * P(t) – 1.0

The function can also be defined in terms of hyperbolic tangent as:
P symmetric (t) = tanh(t)

With sigmoid functions, it becomes possible to normalize any range in [-∞, +∞] onto [-1.0, +1.0].

Oil Cooler Assembly for Royal Enfield Thunderbird 350 AVL

May 9th, 2011 No comments
The performance of a IC engine is directly dependent on the difference between the ambient temperature and the exhaust temperature.  If you had learned about IC engines, it is apparent that the power generated is proportional to the temperature difference between the inlet and the outlet feed for the engine.  So, it is critical to operate the engine under low temperature such that maximum power is generated by the engine.  To keep the engine cool, engine oil is used, which also serves as the lubricant for the moving parts.  Engine oil is the blood for an engine and it’s circulation is crucial for maintaining the temperature and low frictional loses.  There is no oil cooler assembly for TB, or for that matter any RE bikes in India. 

Chinmay Dhangre from Pune generously offered to supply a modified oil cooler.  I was excited to read a blog post by Chinmay at http://www.indiancarsbikes.in/automotive-technology/royal-enfield-avl-engine-oil-cooler-update-real-world-data-4175/. When I contacted Chinmay at macasp@gmail.com, he was readily helping me to get the necessary fitments and hardware.

The reason for keep the inlet at a higher position than the outlet is to ensure that some oil is pre-stored in the oil cooler compartment all the time.  When the engine is started, it takes >10 seconds for the oil to reach the rocker, tappet assembly through the Y pipe.  If I had put the oil cooler in the middle, it would take more time to fill the oil cooler and then reach the rocker assembly.  Having this inverted connection helps the oil start its circulation faster.

The oil cooler assembly and the Y pipes are connect via a nylon coated reinforced rubber tube.  While fitting so, care should be taken for keep the pipes away from the silencer tube.  Also, it is to be ensured the the joints don’t leak after they are secured by clamps.  In the above picture, one clamp is missing!

I had used one clamp to offset the nylon pipe from the silencer tube.  I will have to use some other method for this offseting, as I am indeed wasting a good clamp!

While draining the oil during oil replacement, one has to take care of removing the oil in the oil-cooler compartment by opening the bottom vent.  Otherwise, sludge can start to accumulate inside the oil cooler assembly, which could eventually block the oil flow later.  So, it should be practice that the oil cooler assembly is cleaned every time the engine is serviced.

The completed bike is able to keep the engine oil temperature lower by allowing the natural air flow cooling off the oil through the oil-cooler fins.  Do mind that while the bike is stationery, the oil cooler cannot provide any help as it needs air flow for cooling.