models package¶
Submodules¶
models.Ball module¶
-
class
models.Ball.
Ball
(agent, dT, auto=True, init_state=[-5, -5, 0, 0])¶ Bases:
models.KinematicModel.KinematicModel
This the 2D ball model. The robot can move to any direction on the plane.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
add_BB8
(pos, color, scale=0.5)¶
-
add_half_planes
()¶
-
draw_half_plane
(coef)¶
-
draw_valid_half
()¶
-
estimate_state
(obstacle)¶ State estimater caller.
-
get_P
()¶ Return position in the Cartisian space.
-
get_PV
()¶ This function return the cartesian position and velocity of the robot,
- Returns
6*1 array. [x y z vx vy vz]
- Return type
PV (ndarray)
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Xh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
init_x
(init_state)¶ init state x
-
load_model
(render, loader, color=[0.1, 0.5, 0.8, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
remove_half_planes
()¶
-
set_P
(p)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(v)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
test_half
(parent, coef)¶
-
u_ref
()¶ Reference control input.
-
models.Ball3D module¶
-
class
models.Ball3D.
Ball3D
(agent, dT, auto=True, init_state=[-5, -5, 0, 0, 0, 0])¶ Bases:
models.KinematicModel.KinematicModel
This the 3D ball model. The robot can move to any direction.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
add_half_planes
()¶
-
draw_half_plane
(coef)¶
-
draw_valid_half
()¶
-
estimate_state
(obstacle)¶ State estimater caller.
-
get_P
()¶ Return position in the Cartisian space.
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Xh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
init_x
(init_state)¶ init state x
-
load_model
(render, loader, color=[0.1, 0.5, 0.8, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
remove_half_planes
()¶
-
set_P
(p)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(v)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
test_half
(parent, coef)¶
-
u_ref
()¶ Reference control input.
-
models.HumanBall2D module¶
-
class
models.HumanBall2D.
HumanBall2D
(agent, dT, auto=True, init_state=[5, 5, 0, 0])¶ Bases:
models.Ball.Ball
This the passive human 2D ball model. We assume a ball is control by human. The human has no response to the robot.
-
human_model
()¶
-
load_model
(render, loader, color=[0.8, 0.3, 0.2, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
move
(*args)¶ Move phase. An random disturbance is added to the control input.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
rls_estimate_state
(obstacle)¶
-
update
(obstacle)¶ Update phase. 1. update score, 2. update goal, 3. update self state estimation, 4. update the nearest point on self to obstacle, 5. calculate control input, 6. update historical trajectory.
- Parameters
obstacle (KinematicModel()) – the obstacle
-
-
models.HumanBall2D.
rand
(d0, d1, ..., dn)¶ Random values in a given shape.
Create an array of the given shape and populate it with random samples from a uniform distribution over
[0, 1)
.- Parameters
d1, .., dn (d0,) – The dimensions of the returned array, should all be positive. If no argument is given a single Python float is returned.
- Returns
out – Random values.
- Return type
ndarray, shape
(d0, d1, ..., dn)
See also
random()
Notes
This is a convenience function. If you want an interface that takes a shape-tuple as the first argument, refer to np.random.random_sample .
Examples
>>> np.random.rand(3,2) array([[ 0.14022471, 0.96360618], #random [ 0.37601032, 0.25528411], #random [ 0.49313049, 0.94909878]]) #random
-
models.HumanBall2D.
randn
(d0, d1, ..., dn)¶ Return a sample (or samples) from the “standard normal” distribution.
If positive, int_like or int-convertible arguments are provided, randn generates an array of shape
(d0, d1, ..., dn)
, filled with random floats sampled from a univariate “normal” (Gaussian) distribution of mean 0 and variance 1 (if any of the \(d_i\) are floats, they are first converted to integers by truncation). A single float randomly sampled from the distribution is returned if no argument is provided.This is a convenience function. If you want an interface that takes a tuple as the first argument, use numpy.random.standard_normal instead.
- Parameters
d1, .., dn (d0,) – The dimensions of the returned array, should be all positive. If no argument is given a single Python float is returned.
- Returns
Z – A
(d0, d1, ..., dn)
-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied.- Return type
ndarray or float
See also
standard_normal()
Similar, but takes a tuple as its argument.
Notes
For random samples from \(N(\mu, \sigma^2)\), use:
sigma * np.random.randn(...) + mu
Examples
>>> np.random.randn() 2.1923875335537315 #random
Two-by-four array of samples from N(3, 6.25):
>>> 2.5 * np.random.randn(2, 4) + 3 array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random [ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random
models.HumanBall3D module¶
-
class
models.HumanBall3D.
HumanBall3D
(agent, dT, auto=True, init_state=[5, 5, 0, 0, 0, 0])¶ Bases:
models.Ball3D.Ball3D
This the passive human 3D ball model. We assume a ball is control by human. The human has no response to the robot.
-
human_model
()¶
-
load_model
(render, loader, color=[0.8, 0.3, 0.2, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
move
(*args)¶ Move phase. An random disturbance is added to the control input.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
rls_estimate_state
(obstacle)¶
-
update
(obstacle)¶ Update phase. 1. update score, 2. update goal, 3. update self state estimation, 4. update the nearest point on self to obstacle, 5. calculate control input, 6. update historical trajectory.
- Parameters
obstacle (KinematicModel()) – the obstacle
-
models.InteractiveHumanBall2D module¶
-
class
models.InteractiveHumanBall2D.
InteractiveHumanBall2D
(agent, dT, auto=True, init_state=[5, 5, 0, 0])¶ Bases:
models.KinematicModel.KinematicModel
This the interactive human 2D ball model. We assume a ball is control by human. The human will try to avoid collision with the robot.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
estimate_state
(obstacle)¶ State estimater caller.
-
get_P
()¶ Return position in the Cartisian space.
-
get_PV
()¶ This function return the cartesian position and velocity of the robot,
- Returns
6*1 array. [x y z vx vy vz]
- Return type
PV (ndarray)
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Xh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
init_x
(init_state)¶ init state x
-
load_model
(render, loader, color=[0.8, 0.3, 0.2, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
set_P
(p)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(v)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
u_ref
()¶ Reference control input.
-
models.InteractiveHumanBall3D module¶
-
class
models.InteractiveHumanBall3D.
InteractiveHumanBall3D
(agent, dT, auto=True, init_state=[5, 5, 0, 0, 0, 0])¶ Bases:
models.KinematicModel.KinematicModel
This the interactive human 3D ball model. We assume a ball is control by human. The human will try to avoid collision with the robot.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
estimate_state
(obstacle)¶ State estimater caller.
-
get_P
()¶ Return position in the Cartisian space.
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Xh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
init_x
(init_state)¶ init state x
-
load_model
(render, loader, color=[0.8, 0.3, 0.2, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
set_P
(p)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(v)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
u_ref
()¶ Reference control input.
-
models.KinematicModel module¶
-
class
models.KinematicModel.
KinematicModel
(init_state, agent, dT, auto, is_2D=False)¶ Bases:
object
This is the base class for all robot dynamic models. We assume the models are all in the form:
\(X' = A * X + B * u\)
\(\dot X = fx + fu * u\)
Because
\(X' = X + \dot X * dT\)
Then
\(fx = (A - I) / dT\)
\(fu = B / dT\)
We just need to specify A and B to define different dynamic models.
There are two major phases in the control circle, update and move. In the update phase, the robot will update its information based on the environment. And in the move phase, the robot will execute control input.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
add_sphere
(pos, color, scale=0.5)¶ Add a sphere model into the scene.
- Parameters
pos – position to place the sphere
color – color of the sphere
scale – scale to zoom the sphere
-
calc_control
(obstacle)¶ Generate control input by the agent.
- Parameters
obstacle (KinematicModel()) – the obstacle
-
dot_X
()¶ First order estimation of dot_X using current state and last state.
-
draw_movement
(X, u)¶ For debug use. Show the velocity vector and control vector.
-
draw_trace
()¶ Show the trace of the end effector.
-
estimate_state
()¶ State estimater caller.
-
filt_u
(u)¶ return the saturated control input based the given reference control input
- Parameters
u (ndarray) – reference control input
- Returns
saturated control input
- Return type
u (ndarray)
-
filt_x
(x)¶ return the saturated robot state based the given reference state
- Parameters
x (ndarray) – reference state
- Returns
saturated state
- Return type
x (ndarray)
-
fu
()¶ This function calculate fu from B, Because X’ = X + dot_X * dT Then fu = B / dT
-
fx
()¶ This function calculate fx from A, Because X’ = X + dot_X * dT Then fx = (A - I) / dT
-
get_P
()¶ Return position in the Cartisian space.
-
get_PV
()¶ This function return the cartesian position and velocity of the robot,
- Returns
6*1 array. [x y z vx vy vz]
- Return type
PV (ndarray)
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Mh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
init_x
(init_state)¶ init state x
-
kalman_estimate_state
()¶ Use kalman filter to update the self state estimation.
-
load_model
(render, loader, color=[0.1, 0.5, 0.8, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
move
()¶ Move phase. An random disturbance is added to the control input.
-
move_seg
(vdata, p_from, vec)¶ Move a segment line to a new position.
- Parameters
vdata – segment line handle
p_from – new start point
vec – the segment line vector
-
observe
(x)¶
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
reset
(dT, goals)¶ This function reset the robot state to initial, and set the goals to given goals. This function is useful when the user need to make sure all the robot are tested under the same goal sequence,
- Parameters
dT (float) – the seperation between two control output
goals (ndarray) – n*6 array of goal specification. [x y z 0 0 0]
-
set_P
(p)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(v)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_X
(x)¶
-
set_goals
(goals)¶
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
u_ref
()¶ Reference control input.
-
update
(obstacle)¶ Update phase. 1. update score, 2. update goal, 3. update self state estimation, 4. update the nearest point on self to obstacle, 5. calculate control input, 6. update historical trajectory.
- Parameters
obstacle (KinematicModel()) – the obstacle
-
update_goal
()¶
-
update_m
(Mh)¶ Update the nearest cartesian point on self to obstacle. :param Mh: 6*1 array, cartesian postion and velocity of the obstacle. :type Mh: ndarray
-
update_score
(obstacle)¶ Update the scores of the robot based on the relative postion and relative velocity to the obstacle. The scores are used to draw roc curves and generate statistical restuls.
- Parameters
obstacle (KinematicModel()) – the obstacle
-
update_trace
()¶ update trace of end effector
-
models.RobotArm module¶
-
class
models.RobotArm.
RobotArm
(agent, dT, auto=True, init_state=[-4, -4, 0, 0, 1.5707963267948966, -1.5707963267948966, -1.5707963267948966, 4.5, 4.5, 2])¶ Bases:
models.KinematicModel.KinematicModel
This is the 4 DoF robot arm model.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
Jacobbian
(lm)¶
-
aux_mat
()¶
-
f
(x, g)¶
-
filt_u
(u)¶ return the saturated control input based the given reference control input
- Parameters
u (ndarray) – reference control input
- Returns
saturated control input
- Return type
u (ndarray)
-
filt_x
(x)¶ return the saturated robot state based the given reference state
- Parameters
x (ndarray) – reference state
- Returns
saturated state
- Return type
x (ndarray)
-
get_P
()¶ Return position in the Cartisian space.
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Mh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
get_ev
(x)¶
-
gradient_f
(x, g)¶
-
init_x
(init_state)¶ init state x
-
inv_J
()¶
-
load_model
(render, loader, color=[0.1, 0.5, 0.8, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
p_P_p_X
()¶
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
set_P
(theta)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(dot_theta)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
u_ref
()¶ Reference control input.
-
models.SCARA module¶
-
class
models.SCARA.
SCARA
(agent, dT, auto=True, init_state=[-4, -4, 0, 0, 4.5, 4.5])¶ Bases:
models.KinematicModel.KinematicModel
This is the SCARA model, a 2 DoF plane robot.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
Jacobbian
(lm)¶
-
filt_u
(u)¶ return the saturated control input based the given reference control input
- Parameters
u (ndarray) – reference control input
- Returns
saturated control input
- Return type
u (ndarray)
-
filt_x
(x)¶ return the saturated robot state based the given reference state
- Parameters
x (ndarray) – reference state
- Returns
saturated state
- Return type
x (ndarray)
-
get_P
()¶ Return position in the Cartisian space.
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Xh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
get_ev
(x)¶
-
init_x
(init_state)¶ init state x
-
inv_J
()¶
-
load_model
(render, loader, color=[0.1, 0.5, 0.8, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
p_P_p_X
()¶
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
set_P
(theta)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(dot_theta)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
u_ref
()¶ Reference control input.
-
models.Unicycle module¶
-
class
models.Unicycle.
Unicycle
(agent, dT, auto=True, init_state=[-5, -5, 0, 0])¶ Bases:
models.KinematicModel.KinematicModel
This is the unicycle model, the robot can only turn around and move forward and backward.
-
A
()¶ Transition matrix A as explained in the class definition.
-
B
()¶ Transition matrix B as explained in the class definition.
-
filt_u
(u)¶ return the saturated control input based the given reference control input
- Parameters
u (ndarray) – reference control input
- Returns
saturated control input
- Return type
u (ndarray)
-
filt_x
(x)¶ return the saturated robot state based the given reference state
- Parameters
x (ndarray) – reference state
- Returns
saturated state
- Return type
x (ndarray)
-
get_P
()¶ Return position in the Cartisian space.
-
get_V
()¶ Return velocity in the Cartisian space.
-
get_closest_X
(Xh)¶ Update the corresponding state of the nearest cartesian point on self to obstacle.
- Parameters
Mh (ndarray) – 6*1 array, cartesian postion and velocity of the obstacle.
-
init_x
(init_state)¶ init state x
-
load_R2D2
(pos, color, scale)¶
-
load_model
(render, loader, color=[0.1, 0.5, 0.8, 0.8], scale=0.5)¶ Load the 3d model to be shown in the GUI
- Parameters
render – panda3d component
loader – panda3d component
color (list) – RGB and alpha
scale (float) – scale to zoom the loaded 3d model.
-
model_auxiliary
()¶ This function is for debug use.
-
p_M_p_X
()¶ dM / dX, the derivative of the nearest cartesian point to robot state.
-
redraw_model
()¶ Refresh the position of the robot model and goal model in the GUI.
-
set_P
(p)¶ Set position in the Cartisian space.
- Parameters
p (ndarray) – position
-
set_V
(v)¶ Set velocity in the Cartisian space
- Parameters
v (ndarray) – velocity
-
set_saturation
()¶ Set min and max cut off for state x and control u.
-
u_ref
()¶ Reference control input.
-