# How can body segments be moved to precise angles in snake robot?

I want to create an EV3 robot similar to this: I've glanced at the mentioned papers. To me it seems that some simpler equations to govern the motors will work also.

I have 9 segments, articulated by 8 motors (two intelligent bricks daisy-chained).

I want the angles of the segments to be proportional to a sine. Doing some calculations in some graphing software, this should be sufficient to have the snake move in a wave.

However, there seems to be no robust, reliable way to set an angle on an EV3 motor. I have a MoveTo myblock, where I use the motor first as angle sensor, calculate the difference to the desired angle and then set the motor "on" for that amount. I also tried setting the power proportional to the difference. But I do not succeed is setting the angle accurate enough, it starts drifting or overshoots. I can't synchronize all the segments that way.

Is it feasible to attempt this in the graphic programming language that comes with the ev3 software or do I need to look to something more advanced?

Any hints would be appreciated.

Edit: Made some headway, rather than putting the motor "On" for a number of degrees, I simply place the motor "On" with a power proportional to the error between the measured angle and desired angle. Works good enough for now. This is the P in a PID-controller, adding an integration and derivative part might help. The problem I'm currently facing is the weight distribution, the segment that is the head of the snake doesn't have a motor and hence is much lighter. I need to find a better set of factors to multiply the errors with for each motor. I'm confident I'll succeed in this by trial and error whenever I find the time.

• I would try to have tape on each segment at 45° angles and have the color sensor read it. May or may not work, but it is at least half an idea. I would go for an arduino or something though to help, or do the entire snake. Feb 9, 2017 at 4:09
• Welcome to LEGO Answers! Even if you use the same amount of power each time you may get wildly different results depending on the friction of the surface and the arrangement of the motors. You may need to constantly query the data from the rotation sensor(s) to see if it is aligned, and if not perform corrections, making clockwise/counter-clockwise rotations to get a more precise arrangement. Are you able to show us what your program looks like at the moment?
– Ambo100
Feb 10, 2017 at 17:15

if you want the snake to sway left but then automatically sway right then just hook do something like this but like the following: 