-
I've got a piece of code that does nothing more than continuously reading the pitch value of a Technic Hub. from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor, UltrasonicSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.geometry import Axis
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
from usys import stdin, stdout
hub = TechnicHub(Axis.X, Axis.Z)
hub.light.on(Color.GREEN)
motor_left = Motor(Port.A, Direction.COUNTERCLOCKWISE)
motor_right = Motor(Port.B)
motors = [
motor_right,
motor_left
]
while(True):
wait(500)
tilt = hub.imu.tilt()[0]
print(str(tilt))
# for motor in motors:
# motor.run(1000) An example output of this when putting the hub against a static object is this:
This is exactly what I would expect. A constant value. When I then enable the motor lines of code and run again:
The values go all over the place. The motors have nothing attached to them so the hub stays in the exact same position as before. Any idea what's going on or what I can test more to find out the cause? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Could this be vibrations? What do you get if you hold the motor in your hands, not directly against the hub? If so, the we can probably make it less sensitive to this by incorporating the gyro information. We currently only use the accelerometer for tilt. |
Beta Was this translation helpful? Give feedback.
Here you are:
-27 -27 -27 -27 -27 -27 -27 -27 -27 -26
Quite steady it is!
I find it fascinating that those small vibrations cause that large of changes in the angle measurements. I was trying to use the pitch for making a balancing bot with PID algorithm but it didn't really seem to behave as I wanted. This may very well be a big influencer on the malbehaviour.