0
$\begingroup$

I understand this isn't for programming but it's easy to read. I have referenced This for a guide on how to move a 3 wheel omni robot but I have encountered a few problems.

speed = 100
heading = 45
a1 = 90
a2 = 210
a3 = 330

o1 = a1 - heading
m1 = speed * math.sin(o1)

o2 = a2 - heading
m2 = speed * math.sin(o2)

o3 = a3 - heading
m3 = speed * math.sin(o3)

The heading is the angle from X clockwise so 90 being directly up. When I input a heading of 45 it is expected that m1 = 100, m2 = 0 and m3 = -100 yet I get m1 = 85, m2 = 100 and m3 = 77 what could be the problem here?

$\endgroup$
1
  • $\begingroup$ I believe the motor values should be: m1 = 70.71, m2 = 25.88, m3 = -96.59 $\endgroup$
    – Ben
    Commented Dec 1, 2021 at 18:46

1 Answer 1

1
$\begingroup$

I think this is a degrees/radians issue, but I'm not sure how you're expecting the numbers you've got. Consider your inputs:

speed = 100
heading = 45
a1 = 90
o1 = a1 - heading
m1 = speed * math.sin(o1)

Then I would expect o1 = 90 - 45, or o1 = 45, and then I would expect m1 = 100 * sin(45). Here's where it's not clear. Typically I would expect a trig function like sine, cosine, tangent, etc. to take the input in radians unless the document explicitly states otherwise.

Let's assume it is in degrees, though. In that case, the sine of 45 degrees is 0.7071, and so I would expect (in degrees) m1 = 100 * 0.7071 or m1 = 70.71. You stated you're expecting it to be 100, so I'm not sure where that's coming from.

However, what if the math.sin is treating your input as being in radians? Well, 45 radians is a TON - multiply by 360 and divide by $2\pi$ to get 45rad = 2578.4deg. What is the sine of 2,578.4 degrees? 0.852. So, if you're passing in 45 radians, then you wind up with m1 = 100 * 0.852 or m1 = 85.2. If you're casting to int or something then you wind up with m1 = 85, which is what you got.

For m2, you're taking 210-45 and then treating that as radians, but 165rad = 9454deg. Then, sine of 9,454 degrees is 0.998, and you wind up with m2 = 99.8, which rounds to 100.

Try converting to radians first and double-check your expected values and hopefully that gets everything straight for you :)

$\endgroup$
1
  • 1
    $\begingroup$ I see where I messed up, I got so caught between using X for degrees that it didn't occur to me that 45 degrees wasn't diagonal for a 3 wheel robot. Converting to radians has now given values that are correct so thank you 👍 $\endgroup$
    – JRH3221
    Commented Dec 2, 2021 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.