stanfordnmbl / osim-rl

Reinforcement learning environments with musculoskeletal models
http://osim-rl.stanford.edu/
MIT License
877 stars 248 forks source link

Improve interface for coordinate variables in the observation dictionary #216

Open mitkof6 opened 4 years ago

mitkof6 commented 4 years ago

Instead of iterating over the joints to get the generalized coordinate, velocities and accelerations for the observations, I would prefer to iterate over the coordinates in the compute_state_desc. You can update the code as follows if you agree:

        ## Coordinates
        res['coordinate_pos'] = {}
        res['coordinate_vel'] = {}
        res['coordinate_acc'] = {}
        for i in range(self.coordinateSet.getSize()):
            coordinate = self.coordinateSet.get(i)
            name = coordinate.getName()
            res['coordinate_pos'][name] = coordinate.getValue(self.state)
            res['coordinate_vel'][name] = coordinate.getSpeedValue(self.state)
            res['coordinate_acc'][name] = coordinate.getAccelerationValue(self.state)

This is cleaner, because a joint might have more than one coordinates and also we know the name of the coordinate instead of the joint. For example, if you do an imitation learning you might want to compare coordinates directly.