Sunday 27 September 2015

Drive challenges and tweaks

X2 is now all wired up and working.  But here is where the fun began. :D

I had a funny noise coming from the drive.  It haddn't happened during testing.  But i had bought a 2x32 Sabetertooth to run it, and eventually i found it was the ESC settings, limiting the current.  So that seemed to solve it.  But no, after a few mins running the problem would return.  It didn't take long to work out the problems, but i had already started down a side mission.

The mix from the stick to the motor speeds on BHD has always been my way,  Basically, adding and removing the X value from centre, from the Y value from centre.  This had a few key points.
1.  Turning was able to be factored so that drive and turn felt very different.
2.  At max foot speed on one motor you cant add to it, so max range driving differs to in range.

So after a little researching and a lot of simple maths it all came down to a few lines. This was the inspiration, and the base for hte method:
http://www.rchordata.com/files/Using%20Diamond%20Coordinates%20to%20Power%20a%20Differential%20Drive.pdf

This one has the following:
1.  Turn and drive are equal, so full spin is full forward and full back on the motors.
2.  This map is true in that it adjusts both motors for better control, especially at top end.

Map stick input to easy grid -100 to 100 in both axis, including deadzones.
Then constrain the coordinates into a diamond shape.  Using 2 line equations using coordinate geometry to find the intersect, boiled down to the minimum equation.
So if (YDist>(XDist+100)) {  //  if outside top left.  equation of line is y=x+100, so if y > x+100 then it is above line.
OK, the first fun bit. :)  so for the 2 lines this is always true y = m1*x + b1 and y = m2*x - b2
y - y = m1*x + b1  - m2*x - b2  or 0 = (m1 - m2)*x + b1 - b2
We have y = x+100 and y = ((change in y)/Change in x))x
So:   x = -100/(1-(change in y)/Change in x)) and using y = x+100 we can find y with the new x
or:
            XDist = -100/(1-(YDist/XDist));
            YDist = XDist+100;
          } else if (YDist>(100-XDist)) {  //  if outside top right
            // repeat intesection for y = 100 - x
            XDist = -100/(-1-(YDist/XDist));
            YDist = -XDist+100;
          } else if (YDist<(-XDist-100)) {  //  if outside bottom left
            // repeat intesection for y = -x - 100
            XDist = 100/(-1-(YDist/XDist));
            YDist = -XDist-100;
          } else if (YDist<(XDist-100)) {  //  if outside bottom right
            // repeat intesection for y = x - 100
            XDist = 100/(1-(YDist/XDist));
            YDist = XDist-100;
          }
So all coordinates are now in the diamond.
Then we need to map a diagonal 100x100 grid onto the diamond and find the motor speeds.
For the left motor, send ray to y = x + 100 from coordinates along y = -x + b
Find for b, solve for coordinates and resut in y then scale using y = (y - max/2)*2
          int LeftSpeed = ((XDist+YDist-100)/2)+100;
          LeftSpeed = (LeftSpeed-50)*2;
For right send ray to y = -x + Max from coordinates along y = x + b find intersction coordinates and then use the Y vaule and scale.
          int RightSpeed = ((YDist-XDist-100)/2)+100;
          RightSpeed = (RightSpeed-50)*2;
This results in a -100 to 100 range of speeds, so map to usable range.
          LeftSpeed = (map(LeftSpeed, -100, 100, FootMaxReverse, FootMaxForward));
          RightSpeed = (map(RightSpeed, -100, 100, FootMaxReverse, FootMaxForward));

Easy and a completely new mix. :D  Works great, and feels a lot more controllable, especially with the rework on the PS2 buffering issues.  The mix is great.

But that wasnt what i wanted.  I was going to look for a way of driving forwards or backwards on both motors only.  But hey ho. :D  Will try again.

Chis James was in the UK so popped in.  He spotted the supply lead was getting warm, so we upgraded that and it was like a different droid. :D  But then started throwing tracks. :(  And popping wheelies as soon as we added the dome.

The wheelies were a balance and shocks issue.  The suspension is too soft in front when fully loaded, so it is stored energy into the wheelie.  So i decided, for now, to cover the shaft of the damper with rubber washers, so there is some give, but not as much and can run loaded.  Also i looked at the setup and the front height has crept up with the changes, so that was about 15mm too high, so lowered the ride and the adjusted spring and it was a lot better, but still had a tenancy to pop.  So i added about a kilo of Lead to the front of the foot and it seems much more stable.

The shock shoulders rubber bushes have worn already and the holes are now sloppy, they were the uber soft ones, so the 72A are out, and 89A are next. :D  On order. :)  That will help with the rigidity and the wheelies too.

Eventually i spotted it was always the same track when it threw one.  So James and i striped them, got the adjuster moving and set them up properly.  The difference was brilliant.  He now skips over the grass rather than the tracks gripping and twisting, they turn with the feet a lot more than dragging.

I am going to redo the centre, the caster has a lot of slop in the bearing and the noise is pants.

So after a lot more playing, i now have him driving pretty well, and under better control than BHD. :)  The fast and slow modes are setup for in and outdoor use and should work well. :)  I eventually went with the ramping via BHD and a linear map on the drive.  That gave me the best adjustable control via the pad.  But i now have all the failsafes, voltage levels and battery types etc set on the Sabertooth.

The mancave is the ultimate droid tight spaces challenge,  :D   He is now easy to drive even in the tight walkway past the bench, where there is only about 5" clearance total.  I couldn't even get him lined up for it at first. :)