Thanks all for your help.

I'm now able to read the accelerometer data without blocking the 3d
rendering: the threads idea made it. Thanks deavid.

Unfortunately though, I'm still not able to create what I'd like to
do. Basically mimic the movement of the pysical cube containing the
accelerometer on the virtual cube from Soya. Something similar to
http://www.youtube.com/watch?v=BJeohcZssBU

In this video you see what my current code does:
http://www.varesano.net/temp/accelerometer_soya3d_help.ogv

The code is available at http://pastebin.com/mYiB9dWh

So, using turn_x I rotate the cube of X degrees but this happens at
each call of begin_round.. What I'd like to do is to rotate the cube
only if the current angle is different from the one read from the
accelerometer.

Somehow turn_x() has memory: if I rotated 20° in round one, 10° in
round two and then 30° then the cube has actually rotated 60°.

Instead I need it to only place it so that the rotation is only the
last one.

How can I do that?

Thanks,

Fabio Varesano

On 08/21/2010 09:30 PM, deavid wrote:
> 2010/8/21 Fabio Varesano <fabio.vares...@gmail.com>:
>> Hi David,
>>
>> thanks for your input. Unfortunately I don't think that readline() is
>> the problem here.
>>
>> Of course, readline() is blocking until it gets a '\n' but I'm sending
>> something like 200/300 lines/seconds with Arduino (each line contains
>> an ending '\n' see Arduino code at http://arduino.pastebin.com/KNAmnScS).
>>
>> This is actually confirmed if I uncomment the print x_rot statement:
>> this would result in lot of prints in the Python stdout meaning that
>> the read has been successful and fast.
>>
>> FV
>>
> 
> you are rotating inside begin_round, which is wrong.
> 
> You should do the following: in one side (probably a thread), you
> should read the data from the serial port and accumulate it.
> In the other side (soya's main thread), inside the begin_round
> function you should read the accumulated data and put it inside some
> object variables (like rot_inertia_x and so). Then,
> advance_time(proportion) function will get called several times, each
> one with a proportion value. Always, between begin_round and end_round
> are N advance_time calls and the sum of proportion argument for those
> calls will be 1.
> So you should rotate there, in advance_time, but multiplied per proportion.
> 
> If really the code used to read the data from serial takes less than
> 1ms, you can put it in begin_round directly (so no threading is
> required), but i prefer to do threading.
> 
> Take in account that in a 3D app, each funciton gets called over 50
> times per second (or more), a small amount of time spent inside of
> them counts a lot.
> 
> _______________________________________________
> Soya-user mailing list
> Soya-user@gna.org
> https://mail.gna.org/listinfo/soya-user

_______________________________________________
Soya-user mailing list
Soya-user@gna.org
https://mail.gna.org/listinfo/soya-user

Reply via email to