python - blender not responding to my accelerometer motion -


m using arduino interact accelerometer mma7361l blender2.49.using python 2.62. arduino code :

void setup() {   serial.begin(9600); }  void loop() {   serial.print(analogread(0)/4, byte);    //x-axis   serial.print(analogread(1)/4, byte);    //y-axis   serial.print(analogread(2)/4, byte);    //z-axis   delay(40); } 

my python code is:

import blender import gamelogic import serial  serialport = serial.serial('com4', 9600) ob = blender.object.get ('cube') cont=gamelogic.getcurrentcontroller() own = cont.owner rotxx = move.drot[0] rotyy = move.drot[1] rotzz = move.drot[2] move = cont.actuators["move"] blender.window.waitcursor(1) x=[0,0,0] in range(1, 100):     x1[0] = serialport.read(size=1)     x1[1] = serialport.read(size=1)     x1[2] = serialport.read(size=1)      x2=[(((m - n)*1.65)/180) m,n in zip(x,x1)]     rotxx = rotxx + x2[0]     rotyy = rotyy + x2[1]     rotzz = rotzz + x2[2]     move.drot=(rotxx,rotyy,rotzz)     cont.activate(move)     x1=x  else:     serialport.close()     blender.window.waitcursor(0) 

have made sensor actuator connection.. no errors shown in implementation blender cube shows no movement.

in python code, read sensor values coming on serial port 100 times, 4 seconds worth of sensor data @ 40 ms per update (according processing code). need read sensor values , update scene orientation, use while loop this:

read_sensors = true while(read_sensors):     # call serialport.read() read current sensor values     # update scene 

make sure can run @ least every 40 milliseconds, since that's how you're having arduino board write accelerometer values serial port. if don't read data serial port enough buffer, causing values appearing in serialport.read() lag behind current accelerometer values arduino board reading. won't interactive.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -