hmartiro / project-thesis

xJüs, the hexapodal robot with a passive-backbone to improve behavior over harsh terrain.
4 stars 2 forks source link

Develop Power Consumption Script in EPOS #95

Closed PayneTrain closed 11 years ago

PayneTrain commented 11 years ago

Opened issue:

Hello,

I am writing a script in C++ in a Linux environment to monitor the power consumed by the motors during their operation.

Since Power = Voltage x Current, I want to first use the data logger to query sample the motor's actual current value. To do this, I plan to activate a channel using VCS_ActivateChannel() with the ObjectIndex parameter being set to 0x6078, the index of the "Current Actual Value". Is this correct? Why does the EPOS Command Library say "Object: 0x2015 - ChannelNumber" in red next to the ObjectIndex row in section 7.1.5 "Activate Channel".

Do you recommend I use the 'Average Current Value" rather than the "Actual Current Value"?

I do not see an object that records the voltage that the motor is experiencing. Must I measure this externally in order to complete the power equation described above since?

After activating the channel. Data would then start accumulating or do I need to use another VCS function to start data recording? I can see that I cannot use any of the VCS_StartRecorder, etc. functions because I am using Linux.

Lastly, how do I extract data? Again I can't use VCS_ExportChannelDataToFile since I'm using Linux. How can I export the buffer for a channel to a file using VCS_ExtractChannelDataVector?

Thanks for you help!

PayneTrain commented 11 years ago

It appears this is how to use restype to pass back an array, yet the author brings up a good point that the array should be owned by python, so I am going to rework it so that I pass an array into CPP:

import ctypes

f = ctypes.CDLL('./library.so').function f.restype = ctypes.POINTER(ctypes.c_int * 10) print [i for i in f().contents] # output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Basically there are two changes:

remove numpy-related code and ctypes.cast call since we don't need them.

specify the return type to ctypes.POINTER(ctypes.c_int * 10).

By default foreign functions are assumed to return the C int type, hence we need change it to the desired pointer >type.

BTW, returning a newed array from C code to Python code seems inappropriate. Who and when will free the memory? >It's better to create arrays in Python code and pass them to C code. This way it's clear that the Python code owns the >arrays and takes the responsibility of creating and reclaiming their spaces. "

hmartiro commented 11 years ago

Wouldn't it be easier to make a c function that takes an index as an arg and returns a single number On Apr 9, 2013 1:37 PM, "PayneTrain" notifications@github.com wrote:

It appears this is how to use restype to pass back an array, yet the author brings up a good point that the array should be owned by python, so I am going to rework it so that I pass an array into CPP:

— Reply to this email directly or view it on GitHubhttps://github.com/hmartiro/project-thesis/issues/95#issuecomment-16127941 .

PayneTrain commented 11 years ago

Sure. Probably a little slower since its six python to c calls rather than a single python call resulting in 6 c calls at once, buy yeah definitely easier on me

hmartiro commented 11 years ago

Well, the hypothesis was that the python calls to c take a lot of time, but after trying to optimize the PVT functions it turns out that it seems to have no noticeable effect if C is called 60 times vs one time. I think it's nothing to worry about.

On Tue, Apr 9, 2013 at 1:56 PM, PayneTrain notifications@github.com wrote:

Sure. Probably a little slower since its six python to c calls rather than python calling 6 c calls at once, buy yeah definitely easier on me

— Reply to this email directly or view it on GitHubhttps://github.com/hmartiro/project-thesis/issues/95#issuecomment-16129084 .

hmartiro commented 11 years ago

I think this is a priority now, since we need the numbers before we can optimize anything. What we need:

PayneTrain commented 11 years ago

Crushed.