Any Programmers around here?

Discussion in 'Motorized Bicycle General Discussion' started by Prasinos, Nov 8, 2009.

  1. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    Hey guys I have been thinking about making a dyno for my bikes and I have figured out the hardware part. I plan on using one or two 45lb plates as a flywheel and they will be spun by the back tire of a bike. I will use a mouse or a keyboard along with a cam that will click a button a number of times per revolution.

    So the reason for the title.

    I need a program that will record the time between clicks and possibly output them into an excel file. This way I can just use the first derivative to calculate angular velocity, the second derivative to calculate torque and the third to calculate power. It would be able to make some really nice graphs that could show the difference in power from different upgrades, I think it would be really cool.

    Anyway I don't think it would be that difficult for someone that knew what they were doing. I have acess to labview, matlab, and c++. So if anyone could lend advice, or ideally write this program, I would appreciate it greatly.
     
  2. fall_down_stand_up

    fall_down_stand_up New Member

    Joined:
    Apr 26, 2009
    Messages:
    555
    Likes Received:
    0
    Dyno would be great!!!!!I would like to know the actual output of these 2 stroke china girls....
    John-John
     
  3. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    yea im confident i can do it i just need the program if i want to have pretty graphs.
     
  4. 2door

    2door Moderator
    Staff Member

    Joined:
    Sep 15, 2008
    Messages:
    16,301
    Likes Received:
    25
    Huh?
    Derivative? Velocity? Excel file?
    And I was just starting to understand the chain tensioner thing...
    Tom
     
  5. TheE

    TheE New Member

    Joined:
    Jun 26, 2009
    Messages:
    187
    Likes Received:
    0
    Um yeah, that wouldn't be too hard to do in good ol' fashioned C. Could export the results directly in .csv format too.

    The multi-tasking of a modern OS will throw off the timing a hair, just for fair warning.
     
    #5 TheE, Nov 8, 2009
    Last edited: Nov 8, 2009
  6. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    not to impose, but if i gave you my email could you make the program and send it to me? I dont want to cause you too much trouble and i dont know how complicated the code would be, but if it isnt too hard....
     
  7. TheE

    TheE New Member

    Joined:
    Jun 26, 2009
    Messages:
    187
    Likes Received:
    0
    I've actually been trying to code it a bit. Turns out that getting any kind of precision timing in C is alot harder than I thought. I'll let you know if I find anything.
     
  8. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    hmmm, yea i can only make the flywheel so heavy, if i could get to within like 50 miliseconds i think it would be enough.
     
  9. TheE

    TheE New Member

    Joined:
    Jun 26, 2009
    Messages:
    187
    Likes Received:
    0
    Welp, I did a bit of researching about something called the QueryPerformanceCounter function which, as the name implies, queries a counter inside the CPU for really high-res timing. Here's my code with it so far (for Visual Studio C++):
    Code:
    #include "stdafx.h"
    #include <windows.h>
    
    #include <winbase.h>
    #include <stdlib.h>
    #include <conio.h>
    
    int main(void)
    {
    
    	
        unsigned long int revs=0;
        LARGE_INTEGER total_time,diff_time,start_time,end_time,TICKS_PER_SECOND;
    	char c=0;
    	FILE *outp;
    
    	QueryPerformanceFrequency(&TICKS_PER_SECOND);
    
    	total_time.QuadPart=0;
    	outp=fopen("output.csv","a");
    	fflush(stdin);
    	printf("QPC Freq: %I64d\n",TICKS_PER_SECOND.QuadPart);
    	
    
    	printf("Press any key to begin capturing.\n");
    	
        
    	getch();
    
    	printf("Capturing counts to output.csv, press 'x' to quit...");
    
        QueryPerformanceCounter(&start_time);
    
    	while(c!='x')
    	{
    		if(kbhit())
    		{
    		
    		   QueryPerformanceCounter(&end_time);
    		   diff_time.QuadPart=end_time.QuadPart-start_time.QuadPart;
    		   total_time.QuadPart+=diff_time.QuadPart;
    		   QueryPerformanceCounter(&start_time);
    		   revs++;
    		   fprintf(outp,"%ld,%I64d,%I64d,\n",revs,total_time.QuadPart,diff_time.QuadPart);
    		   c=getch();
    		}
    		
    	}
    
    	fclose(outp);
    
    	printf("\n\nTotal of %ld revolutions were counted!\n",revs);
    	getch();
    
         return EXIT_SUCCESS;
    }
    
    It will tell you how many ticks per second at the beginning, and then append the results into an "output.csv" file in the same directory as the executable(will be created if it hasn't already). You can later multiply (number of ticks * (1/tick frequency)) to get the time.

    I really have no idea how accurate it is, and I'm not a professional programmer by any stretch of the imagination. I'm sure someone will chime in with a better solution. Personally I prefer a microcontroller because you can manually calculate it's timing down to the nanosecond, but a general goes to war with the army he's got...
     
    #9 TheE, Nov 8, 2009
    Last edited: Nov 8, 2009
  10. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    Thanks alot E, il see how this works. I get home around thanksgiving so il let you know how this all goes when i try it ou
     
  11. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    il check it out tommorow i gotta study for a test first.
     
  12. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    K i looked at the code and tried it out just messing around. It doesent seem to be very accurate at all... once you click more than twice a second the times can be off by almost 50 percent. Ive been looking this up and it seems like lots of people are making programs like this but i couldn't find any posted code. I also found many online games that measured exact time between clicks but obvously none of them could outut to excel.....
     
  13. TheE

    TheE New Member

    Joined:
    Jun 26, 2009
    Messages:
    187
    Likes Received:
    0
    How were you checking the timing?

    Did you say you had LabView? It's probably better suited to this kind of thing, I've never used it though.
     
    #13 TheE, Nov 9, 2009
    Last edited: Nov 9, 2009
  14. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    yea it would be pretty easy with labview but i still cant find my license online, i had it last year and Virginia Tech normally keeps those available....
     
  15. xlite

    xlite New Member

    Joined:
    Jun 18, 2009
    Messages:
    736
    Likes Received:
    0
    Don't dynos depend on resistance? 45 lb plates would not have any once up to speed.
     
  16. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    there are literally hundreds of dyno designs, mine would use the moment of inertia of a flywheel. Torque=(angular acceleration) x (moment of inertia). So id use the program to record the angular acceleration and i would calculate the moment of inertia of the flywheel, so using both the values i can calculate torque. Then you just multiply that by angular velocity to get power.


    Yea im working on labview and i think this owuld be pretty easy if i can just get my licence for it back...
     
  17. Dan

    Dan Staff
    Staff Member

    Joined:
    May 25, 2008
    Messages:
    12,474
    Likes Received:
    49

    Har, lol. Me 2!
     
  18. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    k boys looks like i can get labiew i just need to fill out some paperwork to renew my license. Il take care of that part tommorow and see what i can do as far as code is concerned.
     
  19. Prasinos

    Prasinos New Member

    Joined:
    Dec 1, 2008
    Messages:
    257
    Likes Received:
    0
    I just got labview and i have no idea what im doing, i cant figure out how to make a loop that records the time between clicks, can anyone help...
     
  20. xlite

    xlite New Member

    Joined:
    Jun 18, 2009
    Messages:
    736
    Likes Received:
    0
    Yes... I understand now. Dynamic. I looked at building a water paddle type dyno but ended up using a long gradual hill nearby in conjunction with a GPS to get a relative idea of engine performance.

    Like TheE I am inclined to do this type of logging with a cheap AVR or PIC micro and download result to a PC instead of trying to make the PC do reliable low level timimg. It seems to get worse with each new version of Windoze.
     

Share This Page