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

[python/viewer] Fix meshcat backend. #408

Merged
merged 8 commits into from
Sep 5, 2021
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/manylinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Build project dependencies
run: |
./build_tools/build_install_deps_linux.sh
"${PYTHON_EXECUTABLE}" -m pip install "gym>=0.18.3" "stable_baselines3>=0.10" "importlib-metadata>=3.3.0"
"${PYTHON_EXECUTABLE}" -m pip install --prefer-binary "gym>=0.18.3" "stable_baselines3>=0.10" "importlib-metadata>=3.3.0"

#####################################################################################

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
"${PYTHON_EXECUTABLE}" -m pip install --upgrade numpy
"${PYTHON_EXECUTABLE}" -m pip install tensorflow
"${PYTHON_EXECUTABLE}" -m pip install "torch==1.8.0+cpu" -f https://download.pytorch.org/whl/torch_stable.html
"${PYTHON_EXECUTABLE}" -m pip install "gym>=0.18.3" "stable_baselines3>=0.10" "importlib-metadata>=3.3.0"
"${PYTHON_EXECUTABLE}" -m pip install --prefer-binary "gym>=0.18.3" "stable_baselines3>=0.10" "importlib-metadata>=3.3.0"
"${PYTHON_EXECUTABLE}" -m pip install "ray[default,rllib]<=1.4.0" # Type checking is not working with 1.4.1

#####################################################################################
Expand Down Expand Up @@ -121,6 +121,7 @@ jobs:
--disable=fixme,abstract-method,protected-access,useless-super-delegation \
--disable=too-many-instance-attributes,too-many-arguments,too-few-public-methods,too-many-lines \
--disable=too-many-locals,too-many-branches,too-many-statements \
--disable=unspecified-encoding,logging-fstring-interpolation \
--generated-members=numpy.*,torch.* "gym_jiminy/"

mypy --allow-redefinition --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Build project dependencies
run: |
python -m pip install "torch==1.8.0+cpu" -f https://download.pytorch.org/whl/torch_stable.html
python -m pip install "gym>=0.18.3" "stable_baselines3>=0.10" "importlib-metadata>=3.3.0"
python -m pip install --prefer-binary "gym>=0.18.3" "stable_baselines3>=0.10" "importlib-metadata>=3.3.0"
& "./build_tools/build_install_deps_windows.ps1"

#####################################################################################
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 3.10)

# Set the build version
set(BUILD_VERSION 1.6.29)
set(BUILD_VERSION 1.6.30)

# Set compatibility
if(CMAKE_VERSION VERSION_GREATER "3.11.0")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Beside a strong focus on performance to answer machine learning's need for runni
- C++ core with full python bindings, providing frontend API parity between both languages.
- Designed with machine learning in mind, with seemless wrapping of robots as [OpenAI Gym](https://github.com/openai/gym) environments using one-liners. Jiminy provides both the physical engine and the robot model (including sensors) required for learning.
- Easy to install: `pip` is all that is needed to [get you started](#getting-started) !
- Dedicated integration in jupyter notebook working out-of-the-box - including 3D rendering using [Meshcat](https://github.com/rdeits/MeshCat.jl). This facilitates working on remote headless environnement such as machine learning clusters.
- Dedicated integration in Google Colab, Jupyter Lab, and VSCode working out-of-the-box - including interactive 3D viewer based on [Meshcat](https://github.com/rdeits/MeshCat.jl). This facilitates working on remote headless environnement such as machine learning clusters.
- Cross-platform offscreen rendering capability, without requiring X-server, based on [Panda3d](https://github.com/panda3d/panda3d).
- Rich simulation log output, easily customizable for recording, introspection and debugging. The simulation log is made available in RAM directly for fast access, and can be exported in raw binary, CSV or [HDF5](https://portal.hdfgroup.org/display/HDF5/Introduction+to+HDF5) format.
- Available for both Linux and Windows platforms.
Expand Down
29 changes: 18 additions & 11 deletions core/src/engine/EngineMultiRobot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,9 @@ namespace jiminy
{
stepper_ = std::unique_ptr<AbstractStepper>(
new RungeKuttaDOPRIStepper(systemOde,
robots,
engineOptions_->stepper.tolAbs,
engineOptions_->stepper.tolRel));
robots,
engineOptions_->stepper.tolAbs,
engineOptions_->stepper.tolRel));
}
else if (engineOptions_->stepper.odeSolver == "runge_kutta_4")
{
Expand Down Expand Up @@ -2920,6 +2920,9 @@ namespace jiminy
{
constraint->reset(q, v);
constraint->enable();
auto & frameConstraint = static_cast<FixedFrameConstraint &>(*constraint.get());
vector3_t & positionRef = frameConstraint.getReferenceTransform().translation();
positionRef.noalias() -= depth * nGround;
}
}
}
Expand Down Expand Up @@ -2996,11 +2999,15 @@ namespace jiminy
}
else
{
// Enable fixed frame constraint and reset it if it was disable
// Enable fixed frame constraint and reset it if it was disable,
// then move the reference position at the surface of the ground.
if (!constraint->getIsEnabled())
{
constraint->reset(q, v);
constraint->enable();
auto & frameConstraint = static_cast<FixedFrameConstraint &>(*constraint.get());
vector3_t & positionRef = frameConstraint.getReferenceTransform().translation();
positionRef.noalias() -= depth * nGround;
}
}
}
Expand Down Expand Up @@ -3047,19 +3054,19 @@ namespace jiminy
// Compute normal force
float64_t const fextNormal = - std::min(contactOptions_.stiffness * depth +
contactOptions_.damping * vDepth, 0.0);
fextInWorld = fextNormal * nGround;
fextInWorld.noalias() = fextNormal * nGround;

// Compute friction forces
vector3_t const vTangential = vContactInWorld - vDepth * nGround;
float64_t const vRatio = std::min(vTangential.norm() / contactOptions_.transitionVelocity, 1.0);
float64_t const fextTangential = contactOptions_.friction * vRatio * fextNormal;
fextInWorld -= fextTangential * vTangential;
fextInWorld.noalias() -= fextTangential * vTangential;

// Add blending factor
if (contactOptions_.transitionEps > EPS)
{
float64_t const blendingFactor = -depth / contactOptions_.transitionEps;
float64_t const blendingLaw = std::tanh(2 * blendingFactor);
float64_t const blendingFactor = - depth / contactOptions_.transitionEps;
float64_t const blendingLaw = std::tanh(2.0 * blendingFactor);
fextInWorld *= blendingLaw;
}
}
Expand Down Expand Up @@ -3378,7 +3385,7 @@ namespace jiminy
vectorN_t const & stiffness = mdlDynOptions.flexibilityConfig[i].stiffness;
vectorN_t const & damping = mdlDynOptions.flexibilityConfig[i].damping;

quaternion_t const quat(q.segment<4>(positionIdx).data()); // Only way to initialize with [x,y,z,w] order
quaternion_t const quat(q.segment<4>(positionIdx)); // Only way to initialize with [x,y,z,w] order
vectorN_t const axis = pinocchio::quaternion::log3(quat);
uInternal.segment<3>(velocityIdx).array() +=
- stiffness.array() * axis.array()
Expand Down Expand Up @@ -3756,7 +3763,7 @@ namespace jiminy
i,
pinocchio::LOCAL,
jointJacobian);
uAugmented += jointJacobian.transpose() * fext[i].toVector();
uAugmented.noalias() += jointJacobian.transpose() * fext[i].toVector();
}

// Compute non-linear effects
Expand Down Expand Up @@ -3823,7 +3830,7 @@ namespace jiminy
// Convert the force from local world aligned to local frame
frameIndex_t const & frameIdx = frameConstraint.getFrameIdx();
pinocchio::SE3 const & transformContactInWorld = data.oMf[frameIdx];
forceIt->linear() = transformContactInWorld.rotation().transpose() * fextWorld;
forceIt->linear().noalias() = transformContactInWorld.rotation().transpose() * fextWorld;

// Convert the force from local world aligned to local parent joint
jointIndex_t const & jointIdx = model.frames[frameIdx].parent;
Expand Down
36 changes: 31 additions & 5 deletions core/src/solver/LCPSolvers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,38 @@ namespace jiminy
https://github.com/dartsim/dart/blob/master/dart/constraint/PgsBoxedLcpSolver.cpp */
assert(b.size() > 0 && "The number of inequality constraints must be larger than 0.");

/* Reset shuffling counter.
/* Adapt shuffling indices if the number of indices has changed.
Note that it may converge faster to enforce constraints in reverse order,
since usually constraints bounds dependending on others have lower indices
by design. For instance, for friction, x and y */
indices_.resize(b.size());
std::generate(indices_.begin(), indices_.end(),
[n = static_cast<int64_t>(indices_.size() - 1)]() mutable { return n--; });
lastShuffle_ = 0U; // Do NOT shuffle indices right after initialization
size_t const nIndicesOrig = indices_.size();
size_t const nIndices = b.size();
if (nIndicesOrig < nIndices)
{
indices_.resize(nIndices);
std::generate(indices_.begin() + nIndicesOrig, indices_.end(),
[n = static_cast<uint32_t>(nIndices - 1)]() mutable { return n--; });
}
else if (nIndicesOrig > nIndices)
{
size_t shiftIdx = nIndices;
for (size_t i = 0; i < nIndices; ++i)
{
if (static_cast<size_t>(indices_[i]) >= nIndices)
{
for (size_t j = shiftIdx; j < nIndicesOrig; ++j)
{
++shiftIdx;
if (static_cast<size_t>(indices_[j]) < nIndices)
{
indices_[i] = indices_[j];
break;
}
}
}
}
indices_.resize(nIndices);
}

// Normalizing
for (Eigen::Index i = 0; i < b.size(); ++i)
Expand All @@ -111,6 +135,8 @@ namespace jiminy
bool_t isSuccess = ProjectedGaussSeidelIter(A, b, lo, hi, fIdx, false, true, x);
if (isSuccess)
{
// Do NOT shuffle indices unless necessary to avoid discontinuities
lastShuffle_ = 0U;
return true;
}
}
Expand Down
Loading