# 2019-07-31

I built a PCB to solve a problem I'd been having. It appears to work, though I need to do some load testing later. Fortunately a while ago I picked up some load resistors, which I can throw at the board with my bench power supply and see what explodes. I'll be sure to do this outside and with appropriate PPE.

I've been thinking about ways to cut down on the size of the matrices
that I need for the world map, including doing some reading on sparse
matrices and how to represent those. One idea is to use a set of
3-tuples `[x, y, z]`. Could I add up all of these to generate a
"force" vector that pulls the robot in a specific direction? Imagine
this little map, where `r` is the robot and `+` is an obstacle:

+-3210123+ 2 1 +++++ 0 + r + -1 +++ -2

We have these points:

- (2, 1, 1)
- (1, 1, 1)
- (0, 1, 1)
- (1, 1, 1)
- (2, 1, 1)
- (0, -2, 1)
- (0, 2, 1)
- (-2, -1, 1)
- (-1, -1, 1)
- (0, -1, 1)

Ostensibly, the path vector should point towards (1, -1):

+-3210123+ 2 1 +++++ 0 + r + -1 +++@ -2

So, add these up and we get a vector pointing in the general direction of obstacles. Invert that (and do the appropriate rounding of floating point to integer indices), and maybe?

The resulting vector is [3, -2], which points to:

+-3210123+ 2 1 +++++ 0 + r + -1 +++ -2 @

If we turn it into a normal vector, e.g. v / |v|, we get [0.83, -0.55] - which, when rounded out, gives us 1, -1 (even if just barely!). So this seems right.

If the goal is just to ignore obstacles, this works - obstacles will emit a repelling force that pushes the robot away. There would need to be some attractor (like a nav target), and a way to scale the repelling force so that the nav target doesn't override the need to not crash into things (maybe the repellent force follows an inverse square law). I need to think more about this and generate some more examples. I'm not really sure how to apply the distance weighting yet, though I have some ideas.