loco-3d / crocoddyl

Crocoddyl is an optimal control library for robot control under contact sequence. Its solver is based on various efficient Differential Dynamic Programming (DDP)-like algorithms
BSD 3-Clause "New" or "Revised" License
845 stars 173 forks source link

AttributeError from ActionDataAbstract #927

Closed heli-sudoo closed 3 years ago

heli-sudoo commented 3 years ago

Hello, I was trying to build an action model for a simple planar floating base following the unicycle example, i.e., unicycle.py. Part of the code is shown blow.

class ActionModelMonoped(ActionModelAbstract):
    def __init__(self):
        """ Action model for the Monoped (without legs).
        The transition model of an unicycle system is described as           
        """
        """
        Joint q = [x, y, theta]
        State x = [[q], [qd]]
        Constrol u = [w; p] where w = [fx; fy] is ground reaction force
        p = [px; py] is foot loction
        xd = [qd, w-[0;g]], cross(p-[x;y], u)/I]
        """        
        ActionModelAbstract.__init__(self, StateVector(6), 4)
        self.ActionDataType = ActionDataAbstract
        self.ncost = 10

        self.m = 1
        self.dt = 0.1
        self.g = 9.81
        self.I = np.array([[1]])
        self.costWeights = [1, .03]
        self.unone = np.zeros(self.nu)        
        self.nx = self.state.nx

    def calc(self, data, x, u=None):
        if u is None:
            u = self.unone
        assert (x.shape == (self.nx, ) and u.shape == (self.nu, ))
        assert (data.xnext.shape == (self.nx, ))
        assert (data.costResiduals.shape == (self.ncost, ))      

I got the following error when I was trying to define an ActionModelMonoped object:

Traceback (most recent call last):
  File "test.py", line 14, in <module>
    xs = problem.rollout(us)
  File "/home/wensinglab/HL/FootstepPlanning/ddp_footstep_planning/Monoped.py", line 40, in calc
    assert (data.costResiduals.shape == (self.ncost, ))        
AttributeError: 'ActionDataAbstract' object has no attribute 'costResiduals'

Looks like costResiduals is not a member of ActionDataAbstract. (The costResiduals is used in the unicycle.py example.) Is the definition of ActionDataAbstract in crocoddyl not the same as here?

cmastalli commented 3 years ago

The code that you are using is old and deprecated (more than 1.5 year). You should use our examples and notebooks. Concretely, I suggest you to see this file: https://github.com/loco-3d/crocoddyl/blob/master/examples/notebooks/cartpole_swing_up.py

I will close this issue, but feel free to open / ask questions.