external gauges - real instruments - Printable Version +- Forums (https://www.vdrift.net/Forum) +-- Forum: Project (https://www.vdrift.net/Forum/forumdisplay.php?fid=4) +--- Forum: Development (https://www.vdrift.net/Forum/forumdisplay.php?fid=9) +--- Thread: external gauges - real instruments (/showthread.php?tid=860) external gauges - real instruments - mhc21 - 01-09-2008 Hi All! First of all as a free software fan thank you for making this game I have a phidgets servo controller and i wrote some code in vamosworld.cpp from the vdrift-2007-12-26 src to drive the servo taking values from rpm and speed so you can build external gauges... i made a test yesterday with rpm values and it works ok: Code:`    float mhc_r = Vamos_Geometry::rad_s_to_rpm (current_focus->car->engine ()->rotational_speed () / 50);` the servo i'm using have a 200 degree movment (position from 20 to 220) so by dividing by 50 i get the correct values to drive the servo.. 1000 rpm / 50 = 20 min value, and 11000 / 50 = 220 max value.. if you are interested in this mod i can post some more information, pics or video.. but i'm not an expert and i'm sure that the code could be done better.. and math too keep up with u'r great work!!! mhc - joevenzon - 01-09-2008 Some video would be cool to see. How are you driving the servo? Are you doing it from within the vdrift code or are you sending the RPM out of vdrift to an external application that drives the servo? - mhc21 - 01-09-2008 joevenzon Wrote:Some video would be cool to see. did this quickly.. the tach looks pretty funny!!! http://www.youtube.com/watch?v=yikUX_odesY joevenzon Wrote:How are you driving the servo? Are you doing it from within the vdrift code or are you sending the RPM out of vdrift to an external application that drives the servo? did all within the vdrift code, i just got home from work i'll post all detailed information and code after a shower and some food - thelusiv - 01-09-2008 Looks like it works pretty well, you just need a real gauge cluster now. You should go grab one from a junkyard...they should be pretty cheap. - mhc21 - 01-09-2008 first of all u'll need a phidgetservo offcoure i have a 4 servo board, and the phidget framework installed (wich is pretty simple to use) consider that i use linux ( fedora 8 ) and i did this in the vdrift-2007-12-26 src release i did everything in vamosworld.cpp modified like this: add the includes to make phidgets code work, and some printf commands that i used for debugging: Code:```#include #include ``` then i added this code before the VAMOSWORLD::VAMOSWORLD() line 40 of original vamosworld.cpp: Code:```CPhidgetServoHandle mhcservo; void initMhcServo() { int result; const char *err; //object CPhidgetServo_create (&mhcservo); //apro CPhidget_open((CPhidgetHandle)mhcservo, -1);     //aspetto connessione     if((result = CPhidget_waitForAttachment((CPhidgetHandle)mhcservo, 5000)))     {     CPhidget_getErrorDescription(result, &err);     printf("Problem waiting for attachment: %s\n", err);     } } void deinitMhcServo() { CPhidget_close((CPhidgetHandle)mhcservo); CPhidget_delete((CPhidgetHandle)mhcservo); printf("Chiudo\n"); }``` i copied the float rpm at line 1988 of original file like this to define my float for servo data (explained before), and function to make the servo move (this is all in the VAMOSWORLD:rawHUD() functon): Code:```    float mhc_r = Vamos_Geometry::rad_s_to_rpm (current_focus->car->engine ()->rotational_speed () / 50);     CPhidgetServo_setMotorPosition (mhcservo, 0, mhc_r);``` and at the end of the void VAMOSWORLD::LoadHUD() function at line 2526 of original file i added the my function to init the servo: Code:`initMhcServo();` to make scons compile with this hack u need to modify line 71 of SConscript under ./src folder to add libs: Code:`common_libs = ['SDL_image', 'SDL_net', 'SDL_gfx', 'libbulletcollision', 'libbulletmath', 'vorbisfile', 'phidget21', 'm']` and.. that's it! simple what's bad about all this: the servo init function should be placed somewhere where it's called only once.. maybe when the game load or something like that.. otherwise u need to exit the game every time u finish a race or change track or car the have the servo working.. maybe someone can tell me where is the best place to do so and i can do some testing, and i should do some more practice to understand when to deinit the servo too i should think about some more code to use the entire 200 degree servo movement considering the max rpm for each car.. and btw i'll like a light to indicate the rpm peak like in racing tachometers it would be nice to put it as default part of the game.. i should also write some code fore the speedo, i did a couple of test to indicate max 300 khm whit the servo, and for imput graph too since i have a 4 servo board i can make a complete external gauge display have fun! :lol: - mhc21 - 01-09-2008 thelusiv Wrote:Looks like it works pretty well, you just need a real gauge cluster now. You should go grab one from a junkyard...they should be pretty cheap. i have a friend that work in a Mercedes as a mechanic.. they do a lot of warranty services he told me that i can find me some cool stuff.. i'll post some vids whit rpm and speedo working when i get my hand on something cool - thelusiv - 01-09-2008 It's becoming more and more obvious that there needs to be an interface for getting car data from VDrift. Lots of people have now made projects using car data and everyone has to hack up vamosworld.cpp. We should make it easy to program your own gauges, helmets, simulators, etc. with a simple data collection API. That wouldn't be too hard to do, this might be a good goal to strive towards for the next release. - joevenzon - 01-09-2008 thelusiv Wrote:We should make it easy to program your own gauges, helmets, simulators, etc. with a simple data collection API. Sounds good. It wouldn't be too hard to do and would make a few people happy. What sort of data output methods are desired? UDP? - TF - 01-09-2008 Maybe get a motorcycle tach -- sport bikes rev a lot higher so you'll be able to show a longer RPM range with your servo.