Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
/ brainhack-24 Public archive
generated from TIL-24/til-24-base

Commit

Permalink
Add implementation of send_heading
Browse files Browse the repository at this point in the history
  • Loading branch information
tewenhao committed Jun 1, 2024
1 parent a86abf5 commit 63e3f62
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions autonomy/src/autonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,35 @@ async def send_heading(request: Request):

heading = request_dict["heading"]
print(heading)

# TODO: fill in here
# depends on how your team would like to implement the robotics component

conversion = {
'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'niner': '9'
}

for word, digit in conversion.items():
heading = heading.replace(word, digit)

heading = ''.join(heading.split(' '))
# if we look at robot_env.py, env.pan_cannon(heading) takes in
# a *change* in yaw, not an absolute yaw.
# however, i think the heading given is the ABSOLUTE heading
# so we need to get delta and put it in

# get absolute heading to turn to
heading = int(heading)
if heading > 180:
heading -= 360

# detect delta in yaw
current_yaw = env.get_yaw()
yaw_change = heading - current_yaw

# rebase yaw_delta so that it falls between -180 and 180
if yaw_change > 180:
yaw_change -= 360
elif yaw_change < -180:
yaw_change += 360

# output current yaw and yaw change
print(f'current yaw: {current_yaw}; yaw change: {yaw_change}')

# rotate to heading
await env.pan_cannon(heading)
await env.pan_cannon(yaw_change)
print("taking snapshot")
b_image: bytes = await env.take_snapshot()
return Response(content=b_image, media_type="image/jpeg")
Expand Down

0 comments on commit 63e3f62

Please sign in to comment.