Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes unnecessary call to setdirty! in examples 1 and 3 #599

Merged
merged 1 commit into from
Feb 2, 2021

Conversation

ferrolho
Copy link
Contributor

@ferrolho ferrolho commented Jan 29, 2021

Currently, somewhere in example 1 we can read:

# Let's first set the configurations and velocities of the joints:
set_configuration!(state, shoulder, 0.3)
set_configuration!(state, elbow, 0.4)
set_velocity!(state, shoulder, 1.)
set_velocity!(state, elbow, 2.);
# **Important**: a `MechanismState` contains cache variables that depend on the configurations and velocities of the joints. These need to be invalidated when the configurations and velocities are changed. To do this, call
setdirty!(state)

However, set_configuration! and set_velocity! already call setdirty! from within them:

function set_configuration!(state::MechanismState, joint::Joint, config)
set_configuration!(configuration(state, joint), joint, config)
reset_contact_state!(state)
setdirty!(state)
end

function set_velocity!(state::MechanismState, joint::Joint, vel)
set_velocity!(velocity(state, joint), joint, vel)
reset_contact_state!(state)
setdirty!(state)
end

Perhaps the call to setdirty! is in the examples because in some older version of RBD.jl set_configuration! and set_velocity! didn't invalidate the caches?

Copy link
Collaborator

@rdeits rdeits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes sense to me. What do you think, @tkoolen?

@tkoolen
Copy link
Collaborator

tkoolen commented Feb 2, 2021

Yeah, I suppose this is fine. It's certainly not necessary in these cases and I think it's there for mostly historical reasons, but it'd be good to mention somewhere that there's a need to invalidate the cache manually if you modify q and v without using these methods. I'll try to find a better place for that.

@tkoolen tkoolen merged commit e09fac6 into JuliaRobotics:master Feb 2, 2021
@tkoolen
Copy link
Collaborator

tkoolen commented Feb 2, 2021

And sorry I've been out of the loop for so long.

@ferrolho
Copy link
Contributor Author

ferrolho commented Feb 2, 2021

but it'd be good to mention somewhere that there's a need to invalidate the cache manually

It is mentioned here

"""
$(SIGNATURES)
Return the configuration vector ``q``.
Note that this returns a reference to the underlying data in `state`. The user
is responsible for calling [`setdirty!`](@ref) after modifying this vector to
ensure that dependent cache variables are invalidated.
"""
configuration(state::MechanismState) = state.q

and here

"""
$(SIGNATURES)
Return the velocity vector ``v``.
Note that this function returns a read-write reference to a field in `state`.
The user is responsible for calling [`setdirty!`](@ref) after modifying this
vector to ensure that dependent cache variables are invalidated.
"""
velocity(state::MechanismState) = state.v

(And now there's this issue, too.) 😛

@ferrolho
Copy link
Contributor Author

ferrolho commented Feb 2, 2021

And sorry I've been out of the loop for so long.

I don't see why you have to apologise. I'm sure people know this is something you do pro bono. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants