Using Thymio’s accelerometer to detect changes in slope, and it’s wheels to adjust back to a level position, the robot is able to balance on top of a large ball, such as a yoga ball. When the yoga is rotated slowly, Thymio can move to adjust to rest on top of the yoga ball so it does not fall.
- Copy and paste this code to Aseba Studio to achieve the balancing behavior:
var accBuffer0 = 0,0,0,0 var accBufferPos0 = 0 var accBuffer1 = 0,0,0,0 var accBufferPos1 = 0 var sumacc0 var sumacc1 onevent acc accBuffer0[accBufferPos0] = acc-2 #measure lateral tilt accBufferPos0 = (accBufferPos0 + 1) % 4 sumacc0 = accBuffer0 + accBuffer0 + accBuffer0 + accBuffer0 accBuffer1[accBufferPos1] = acc #measure front tilt accBufferPos1 = (accBufferPos1 + 1) % 4 sumacc1 = accBuffer1 + accBuffer1 + accBuffer1 + accBuffer1 motor.left.target=sumacc0*15+sumacc1*15 # acc0 gives rotation, acc1 gives forward movement motor.right.target=-sumacc0*15+sumacc1*15
This is a video of the result:
Another video showing the same behavior but with a weight to help the adhesion of the wheels on the ball: