Kinematics and frames · University · about 30 min
Turning a vector from one frame into the other, in two dimensions, by hand and in code.
[1 mark]A robot at heading 60 measures (0, 10) in its own frame. What does this print?
import math
def body_to_world(vx, vy, h_deg):
a = math.radians(h_deg)
return (vx * math.cos(a) + vy * math.sin(a),
-vx * math.sin(a) + vy * math.cos(a))
wx, wy = body_to_world(0, 10, 60)
print("wx:", round(wx, 2))
print("wy:", round(wy, 2))[1 mark]A robot at heading 90 slides 10 cm to its own right, the body vector (10, 0). What does this print?
import math a = math.radians(90) vx, vy = 10.0, 0.0 wx = vx * math.cos(a) + vy * math.sin(a) wy = -vx * math.sin(a) + vy * math.cos(a) print(round(wx, 2), round(wy, 2))
[1 mark]A student computes 10 * math.sin(90) for a robot facing +x and gets 8.94 instead of 10. What is wrong?
[1 mark]Which matrix undoes R(h), turning a world vector back into the body frame?
[1 mark]In R(h) as the lesson writes it, the minus sign sits on -sin h below the diagonal. Why there?
[1 mark]This rotates the body vector (3, 4) into the world at heading 37 and back again. What does it print?
import math
def body_to_world(vx, vy, h):
a = math.radians(h)
return vx * math.cos(a) + vy * math.sin(a), -vx * math.sin(a) + vy * math.cos(a)
def world_to_body(wx, wy, h):
a = math.radians(h)
return wx * math.cos(a) - wy * math.sin(a), wx * math.sin(a) + wy * math.cos(a)
wx, wy = body_to_world(3, 4, 37)
bx, by = world_to_body(wx, wy, 37)
print(round(math.hypot(wx, wy), 6), round(bx, 6), round(by, 6))A robot at heading 60 measures (0, 10) in its own frame. Print the same vector in the world frame, as wx: and wy:, worked out with the rotation matrix.
from bugbot import * import math connect() h = 60 vx, vy = 0.0, 10.0
Plan your program here, then type it in and press Run.
world_to_body() and check it against body_to_world() for ten random headings.