Saturday, December 23, 2017

XMSnakeRobot - Servo issues - 13 good channels - 7 do strange dancing

The snake robot -  (link) see photos here - has 20 servos run from 3 x Arduino Nano microcontrollers. As of today 13 of these are working and 7 are mis-behaving. Most common misbehaviour is:

  • Command servo to turn 30 degrees - it turns more than that.
  • Command servo to return to the centre position - it turns in the same direction as before but to its extreme position.

My Arduino code includes code to return all servos to the centre position on reset. This works.
I have tried swapping servos and found that the behaviour is pin-related rather than servo-related.
All 3 Arduino Nanos have the same "sketch" (program code) and similar servos connected. They are misbehaving on different pins.
One Arduino also resets itself when servos encounter loads like lifting the snake robot's head.
[Later - 26 Dec 2017 - that head section Arduino has 40cm of thin cables supplying power. These have a significant voltage drop - typically 5.1 volt dropping to 4.8 V with momentarily dropping lower when servo loads kick in. Fix was to crank up the regulator to 5.35V (small improvement) and add a 470uF capacitor and 39 ohm resistor to the Arduino Nano power supply cable (complete fix).]

Hypothesis: There is a problem with I2C.
I have been trying I2C for the first time so I have put a lot of time into checking that.
Now I have changed to Serial communications with exactly the same effect continuing.
At least I know that I can get I2C to work!

Hypothesis: Servos can cause electrical interference.
I have tried running an Arduino on a separate battery to the Servo power supply. No difference.

Hypothesis: Arduino Nano work overload.
TODO try the  "volatile" coding keyword for my servo array.
The (link) Arduino Reference "Volatile"  - states:
"volatile" -- "Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is a temporary memory location where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate."
Emphasis mine!
[Later - 26 Dec 2017 - made no difference. Wemos board (see below) would not compile so "volatile" is eliminated because I want to leave the way open to using Wemos boards]

Hypothesis: The Arduino Nano is simply too low powered to handle the work I am giving it and it is "falling to pieces under the stress". I have found this forum comment:
(link) desmondcorreia (2011) writes:
I have tested each code independently everything works fine but as soon as i put it together everything goes wrong.
Desmond, You sum up my experience so well!
I do have a WEMOS D1 microcontroller where the specs say it runs at 80 MHz which is a good advance on the 16 MHz of the Arduino Nano. I am considering swapping that in. A little challenging with it being a 3.3 Volt system connecting into my very 5-volt-everywhere snake robot.
[Later - 26 Dec 2017 - changed tail section microcontroller from Nano to Wemos, a major change, and the servo behaviour was the same. This prompted me to do another review of my coding and after digging deep I did find a "bug". Coding fix gave a successful system fix.]

That should be enough to be going on with!


No comments:

Post a Comment