Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now that the simulator and its dependencies have been installed, you can import the modules you'll need for this assignment: [ 4 ] import gymnasium

Now that the simulator and its dependencies have been installed, you can import the modules you'll need for this assignment:
[4] import gymnasium
import numpy as np
import gym_neu_racing
from gymnasium import spaces
from gym_neu_racing.envs.wrappers import StateFeedbackWrapper
import matplotlib.pyplot as plt
from typing import Callable
import
matplotlib.cm as cmx
import matplotlib.colors as colors
from gym_neu_racing import motion_models
import cvxpy as cp
1a) MPPI to move toward a goal coordinate
In this problem, you'll implement a basic version of MPPI and show that it outputs a good rollout to move a robot toward a given goal position.
This part uses the Unicycle kinematic model that's built into the simulator. You should make sure that your get_action method considers the
control limits (otherwise it may command things that the robot can't execute), which may require passing those as arguments to the _
method.
You will probably need to experiment with different numbers of rollouts, cost functions, values, numbers of iterations, etc. to get good
performance.
Keeping this code relatively organized and clean will help for later parts in the assignment, where you build on this implementation. For
example, you are encouraged to define helper methods in your MPPI class to help keep your code organized (e.g., you may want a
score_rollouts and/or plot_rollouts method that get called inside the get_next_action method).
Deliverables:
Implement the MPPI class, in particular the get_next_action method, so that the chosen rollout drives the robot toward the goal
position.
Print the best control sequence your MPPI algorithm came up with (the first row/element of this sequence should be the action that your
get_action returns)
Include a plot that shows the rollouts, start position, goal position, and highlights the best rollout in that iteration, for at least a few
iterations. We expect that the later iterations will give much better rollouts than the first iteration. You should make your axes have the
same scale (e.g., using plt.axis('equal'')).
[] # Create an instance of the mobile robot simulator we'll use this semester
env = gymnasium.make("gym_neu_racing/NEUEmptyWorld-v0")
# Tell the simulator to directly provide the current state vector (no sensors yet)
env = StateFeedbackWrapper(env)
[2] class MPPI:
def (
self,
motion_model=motion_models.Unicycle(),
:
"""." Your implementation here """."
self.motion_model = motion_model
raise NotImplementedError
def get_action(self, initial_state: np.ndarray, goal_pos: np.ndarray):
""u" Your implementation here """.
raise NotImplementedError
return action
You can use the following code to check whether your MPPI implementation is working. After tuning your algorithm, it should be able to come
up with a rollout that ends close to the goal (within 0.1m in 12 distance is close enough):
[] # Initialize the environment (and set random seed so any randomness is repeatable)
np. random. seed (0)
obs, -= env. reset ()
# Set the starting state , theta) and goal position (x,y).
initial_state =np.array([0.0,0.0,0.0])
goal_pos = np.array ([0.5,0.5])
# Instantiate your contoller class
controller = MPPI ()
# Run your control algorithm for 1 step. We'll worry about running your
# algorithm in closed-loop in later parts of the assignment.
action = controller.get_action(initial_state, goal_pos)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Energy, Stability, and Equilibrium Question Content Area

Answered: 1 week ago