Catcoder mars rover solution in c++
## Level 1 - calculate the turn radius ##
## level1 2 - calculate new position and angle
import math
## solution works for this data
WHEELBASE = 1.00
DISTANCE = 1.00
STEERINGANGLE = 30.00
#WHEELBASE = 1.75
#DISTANCE = 3.14
#STEERINGANGLE = -23.00
def calculateTurnRadius(wheelbase, steeringangle):
return round(wheelbase / math.sin(math.radians(steeringangle)), 2)
def calculateNewDirection(wheelbase, steeringangle, distance):
turnRadius = calculateTurnRadius(wheelbase, steeringangle)
theta = distance / turnRadius
#brings theta to within a 180 arc
while theta >= math.pi * 2:
theta -= math.pi * 2
while theta < 0:
theta += math.pi * 2
# calculate theta with basic sin and cos trig
x = turnRadius - (math.cos(theta) * turnRadius)
y = math.sin(theta) * turnRadius
x = abs(round(x, 2))
y = round(y, 2)
theta = math.degrees(theta)
theta = round(theta, 2)
return x, y, theta
print(f"Turn Radius = {calculateTurnRadius(WHEELBASE, STEERINGANGLE)}")
print(f"{calculateNewDirection(WHEELBASE, STEERINGANGLE, DISTANCE)}")
Turn Radius = 2.0
(0.24, 0.96, 28.65)
[1]: https://i.stack.imgur.com/tDY2u.jpg