Python gyroRead for Z value not working properly


#1

Hi,

Does someone who uses the Ultimate Robot with Python could tell me if the function gyroRead(0,3,onRead) to read the z value. If its working properly?

Currently it starts for me with a random value between 180 and -180 and then starts to decrease the value. Rotation changes the value but its still wrong. Read x and y work normally.

The code im testing is:
from megapi import *

def onRead(level):
print(“Gyro Value:%f” %level);

if name == ‘main’:
bot = MegaPi()
bot.start()
while 1:
sleep(0.1);
bot.gyroRead(0,3,onRead);


#2

There have been many previous reports on the gyro z -axis and drifting
https://forum.makeblock.com/t/my-mbot-ranger-gyro-z-value-keep-increasing/7276

My problem in a past life
https://forum.makeblock.com/t/robotic-arm-and-gyro-with-encoder-motor/10423

I am working on a python - mbot problem for oscar. I will then pull out my gyro and try it.


#3

This code worked for me:

from megapi import *
angle = 123

def onRead(level):
global angle
angle = level

bot = MegaPi()
bot.start(’/dev/ttyUSB0’)

sleep(2)
print (“start test”)

while 1:
sleep(2)

bot.gyroRead(P,A, onRead) where P is port sensor is plugged into, A is axis 1, 2 , 3

bot.gyroRead(6,3,onRead)
iangle = int(angle)
print (iangle)

#4

Thank you, dr-roboto.

The code bot.gyroRead (P, A, onRead) works for me but P has to be set to 0 and the gyro sensor has to be connected to port 6 of the RJ25 Shield.

The z-axis drifting is probably caused by the power supply.


#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.