Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/config/diffDriveMpc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type: mpc
n: 3
dof: 3
dt: 0.01
H: 100
time_horizon: 100
interval: 1
weights:
w: 2.0
Expand Down
4 changes: 2 additions & 2 deletions examples/config/planarArmMpc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type: mpc
n: 4
dof: 4
dt: 0.01
H: 10
time_horizon: 10
interval: 1
weights:
w: 5.0
Expand Down
4 changes: 2 additions & 2 deletions examples/config/pointRobotMpc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type: mpc
n: 2
dof: 2
dt: 0.01
H: 10
time_horizon: 10
interval: 1
weights:
w: 10.0
Expand Down
12 changes: 6 additions & 6 deletions examples/makeSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


def main():
N = 10
m = 2
time_horizon = 10
dim_goal = 2
dt = 0.01
#mpcModel = PlanarArmMpcModel(m, N, 4)
#mpcModel = PointRobotMpcModel(m, N)
#mpcModel = DiffDriveMpcModel(2, N)
mpcModel = BoxerMpcModel(N)
#mpcModel = PlanarArmMpcModel(dim_goal, 4, time_horizon)
#mpcModel = PointRobotMpcModel(dim_goal, time_horizon)
#mpcModel = DiffDriveMpcModel(2, time_horizon)
mpcModel = BoxerMpcModel(time_horizon)
mpcModel.setDt(dt)
#mpcModel.setSlack()
mpcModel.setObstacles(1, 2)
Expand Down
10 changes: 5 additions & 5 deletions examples/mpcPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import sys
import forcespro
import gym
import planarenvs.groundRobots
import planarenvs.pointRobot
import planarenvs.nLinkReacher
import planarenvs.ground_robots
import planarenvs.point_robot
import planarenvs.n_link_reacher
import re
from MotionPlanningEnv.sphereObstacle import SphereObstacle
from MotionPlanningGoal.staticSubGoal import StaticSubGoal
Expand Down Expand Up @@ -41,7 +41,7 @@ def main():
return
myMPCPlanner.concretize()
myMPCPlanner.reset()
n = myMPCPlanner.n()
n = myMPCPlanner.dof()
staticGoalDict = {
"m": 2, "w": 1.0, "prime": True, 'indices': [0, 1], 'parent_link': 0, 'child_link': n,
'desired_position': [2, -3], 'epsilon': 0.2, 'type': "staticSubGoal",
Expand All @@ -52,7 +52,7 @@ def main():
if robotType == 'diffDrive':
env = gym.make(envName, render=True, dt=myMPCPlanner.dt())
else:
env = gym.make(envName, render=True, dt=myMPCPlanner.dt(), n=myMPCPlanner.n())
env = gym.make(envName, render=True, dt=myMPCPlanner.dt(), n=myMPCPlanner.dof())
limits = np.array([[-50, ] * n, [50, ] * n])
myMPCPlanner.setJointLimits(limits)
q0 = np.random.random(n)
Expand Down
6 changes: 3 additions & 3 deletions robotmpcs/models/boxerMpcModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class BoxerMpcModel(DiffDriveMpcModel):

def __init__(self, N):
super().__init__(2, N)
def __init__(self, time_horizon):
dim_goal = 2
super().__init__(dim_goal, time_horizon)
self._fk = FkCreator('boxer', 3).fk()
self._modelName = 'boxer'

45 changes: 22 additions & 23 deletions robotmpcs/models/diffDriveMpcModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,47 @@

class DiffDriveMpcModel(MpcModel):

def __init__(self, m, N):
n = 3
super().__init__(m, n, N, initParamMap=False)
self._nx = 8 # [x, y, theta, vel_rel0, vel_rel1, xdot, ydot, thetadot]
self._nu = 2 # [a_l, a_r]
def __init__(self, dim_goal, time_horizon):
dof = 3
super().__init__(dim_goal, dof, time_horizon, initParamMap=False)
self._n_state = 8 # [x, y, theta, vel_rel0, vel_rel1, xdot, ydot, thetadot]
self._n_control_input = 2 # [a_l, a_r]
self._limits = {
"x": {"low": np.ones(self._nx) * -100, "high": np.ones(self._nx) * 100},
"u": {"low": np.ones(self._nu) * -100, "high": np.ones(self._nu) * 100},
"x": {"low": np.ones(self._n_state) * -100, "high": np.ones(self._n_state) * 100},
"u": {"low": np.ones(self._n_control_input) * -100, "high": np.ones(self._n_control_input) * 100},
"s": {"low": np.zeros(1), "high": np.ones(1) * np.inf},
}
self._fk = FkCreator('groundRobot', self._n).fk()
self._fk = FkCreator('groundRobot', self._n_dof).fk()
self.initParamMap()
self._modelName = "diffDrive"

def extractVariables(self, z):
q = z[0: self._n]
qdot = z[self._n:2 * self._n]
vel_rel = z[2*self._n: 2*self._n + self._nu]
qddot = z[-self._nu:]
q = z[0: self._n_dof]
qdot = z[self._n_dof:2 * self._n_dof]
vel_rel = z[2 * self._n_dof: 2 * self._n_dof + self._n_control_input]
qddot = z[-self._n_control_input:]
return q, qdot, qddot, vel_rel

def eval_objectiveCommon(self, z, p):
q, qdot, _, vel = self.extractVariables(z)
w = p[self._paramMap["w"]]
wvel = p[self._paramMap["wvel"]]
g = p[self._paramMap["g"]]
W = diagSX(w, self._m)
Wvel = diagSX(wvel, self._nu)
fk_ee = self._fk.fk(q, self._n, positionOnly=True)[0:self._m]
W = diagSX(w, self._dim_goal)
Wvel = diagSX(wvel, self._n_control_input)
fk_ee = self._fk.fk(q, self._n_dof, positionOnly=True)[0:self._dim_goal]
Jvel = ca.dot(vel, ca.mtimes(Wvel, vel))
err = fk_ee - g
Jx = ca.dot(err, ca.mtimes(W, err))
Jobst = 0
Js = 0
if self._obstaclesInCosts:
obstDistances = 1/ca.vcat(self.eval_obstacleDistances(z, p) )
obstDistances = 1 / ca.vcat(self.eval_obstacleDistances(z, p))
wobst = ca.SX(np.ones(obstDistances.shape[0]) * p[self._paramMap['wobst']])
Wobst = diagSX(wobst, obstDistances.shape[0])
Jobst += ca.dot(obstDistances, ca.mtimes(Wobst, obstDistances))
if self._ns > 0:
s = z[self._nx]
if self._n_slack > 0:
s = z[self._n_state]
ws = p[self._paramMap["ws"]]
Js += ws * s ** 2
return Jx, Jvel, Js, Jobst
Expand All @@ -55,10 +55,10 @@ def computeXdot(self, x, vel):
assert x.size() == (3, 1)
assert vel.size() == (2, 1)
xdot = ca.vertcat(
ca.cos(x[2]) * vel[0],
ca.sin(x[2]) * vel[0],
vel[1],
)
ca.cos(x[2]) * vel[0],
ca.sin(x[2]) * vel[0],
vel[1],
)
return xdot

def continuous_dynamics(self, x, u):
Expand All @@ -70,4 +70,3 @@ def continuous_dynamics(self, x, u):
xddot = ca.SX(np.zeros(3))
state_dot = ca.vertcat(xdot, xddot, veldot)
return state_dot

Loading