1

Probably a very basic question but I'm programming a robot to turn with a gyroscope and have hit the limits of what I can remember from my math classes.

I'm polling for the current angle of robots gyroscope and I can tell the degrees that I need to turn d (values of -360 to 360)

I need the turning power to apply to the wheel motors at each poll interval t. Basically sending t to the left motor and -t to the right motor.

I'm not sure what unit of measurement that t has, but the tests I've run show that if I pass along values under about 6 the wheels don't turn at all and if I pass values over about 110 the robot spins fast enough that it messes with the gyroscope and I loose accuracy.

I'd ideally need a function that generically follows the following sets:

Less than -360 : about -110

-360 to -1 : between -110 to -5.

0 : doesn't matter (but having it be 0 would be nice)

1 to 360 : between 5 and 110

Over 360 : about 110.

The function doesn't have to be exact and I feel something like arc tangent would be a good solution except for the bits in the middle where I don't really know how to get it to just floor out on -5 or 5. Also the micro-controller i'm running this on seems to take a while to run a math.atan for some reason which slows down the poll interval (not a big deal if i'm supplying the right power to get there in only a few intervals though).

Thanks for any help!

WhiteleyJ
  • 113
  • What is 6? Time? Seconds? – Moti Dec 24 '19 at 19:29
  • If d set to 55 the robot turns 55? – Moti Dec 24 '19 at 19:31
  • d is the degrees that I need to turn. So if d is 55 i need to turn 55 degrees clockwise. In that specific situation i'd probably want to send the command to supply 70 to 80 amps (volts?) to the motor.

    During the next evaluation of d i= 30, so I'd want to cut the amps supplied to the motor down to something like 25.

    During the next evaluation d = 2 so I'd want to apply 5 amps to the motor.

    Next evaluation d = -1 so i'd want to supply -5 amps to the motor (wiggling it back into position).

    – WhiteleyJ Dec 24 '19 at 20:33
  • You don't say anything about the case where $0 < d < 1.$ Is $d$ an integer number of degrees? – David K Dec 24 '19 at 21:31

1 Answers1

0

I'll generalize this and you can fiddle with the constants until they work well for your particular set of equipment. The function is

$$ t = \begin{cases} m & \text{if } d \geq L, \\ h + \frac{m - h}{L} d & \text{if } 0 < d < L, \\ 0 & \text{if } d = 0, \\ -h + \frac{m - h}{L} d & \text{if } -L < d < 0, \\ -m & \text{if } d \leq -L. \end{cases} $$

A function like this can be encoded by "if else" statements in just about any programming language and should be easier to evaluate than an arc tangent.

You can set $m = 110$, $L = 360,$ and $h = 5$ if you want, though you might get more positive control if you set $L$ to a smaller value so you're not constraining yourself to using less than half power for any turn under $180$ degrees and less than one-quarter power for any turn under $90$ degrees.


Why you would ever make a turn of $270$ degrees rather than $-90$ is another question.

David K
  • 108,155
  • a corner obstacle ... –  Dec 24 '19 at 23:06
  • @RoddyMacPhee OK, I can imagine if you are heading north and need to make a left turn, you could have something sticking out the front of the robot that would hit an obstacle to your northwest, or something in the back that would hit an obstacle to the southeast. The other three quadrants need to be clear for the $270$-degree turn, however, so in all cases except extremely contrived ones you could simply make the turn farther from the obstacle. I'm curious what OP had in mind. – David K Dec 24 '19 at 23:42
  • Hey, the corner obstacle thing was the actual answer for that. For rear wheel drive you have to worry about your robots nose swinging around and getting caught on stuff, for front wheel drive you have to worry about your other end. Any time an arm is sticking out somewhere you have to worry about that as well. – WhiteleyJ Dec 28 '19 at 17:53
  • When you start talking about rear wheel drive (suggesting a rectangular vehicle rotating around a point near one end—not a Roomba like I was imagining) then it is clear how you could find it easier to turn “the long way” in some circumstances. That raises many other questions about motion planning but I suppose those are outside the scope of the question. – David K Dec 31 '19 at 01:12