Draft
Conversation
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Paul Nechifor <paul@nechifor.net>
Greptile OverviewGreptile SummaryThis PR implements a subprocess-based architecture for running MuJoCo simulations on macOS to enable the viewer, which doesn't work in the main process on macOS. Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant SimModule as SimulationModule
participant SimInterface as SimManipInterface
participant MujocoEngine
participant ShmWriter
participant Subprocess as MuJoCo Subprocess
participant ShmReader
participant MujocoSim as MuJoCo Simulation
User->>SimModule: start()
SimModule->>SimInterface: connect()
SimInterface->>MujocoEngine: connect()
alt macOS and not headless
MujocoEngine->>ShmWriter: create shared memory
MujocoEngine->>Subprocess: spawn (mjpython mujoco_process.py)
Subprocess->>ShmReader: attach to shared memory
Subprocess->>MujocoSim: initialize model and viewer
Subprocess->>ShmReader: signal_ready()
MujocoEngine->>ShmWriter: wait for is_ready()
MujocoEngine-->>SimInterface: connected
else Linux or headless
MujocoEngine->>MujocoEngine: start sim_thread
MujocoEngine-->>SimInterface: connected
end
SimInterface-->>SimModule: connected
SimModule->>SimModule: start control_thread
SimModule->>SimModule: start monitor_thread
loop Control Loop (100Hz)
User->>SimModule: publish JointCommand
SimModule->>SimInterface: write_joint_positions()
SimInterface->>MujocoEngine: write_joint_command()
alt subprocess mode
MujocoEngine->>ShmWriter: write_command()
ShmWriter->>ShmWriter: increment seq[0]
Subprocess->>ShmReader: read_command()
ShmReader->>ShmReader: check seq[0]
Subprocess->>MujocoSim: apply control
MujocoSim->>MujocoSim: mj_step()
Subprocess->>ShmReader: write_state()
ShmReader->>ShmReader: increment seq[1]
MujocoEngine->>ShmWriter: read_state()
else threaded mode
MujocoEngine->>MujocoEngine: update targets (with lock)
MujocoEngine->>MujocoSim: apply_control()
MujocoSim->>MujocoSim: mj_step()
MujocoEngine->>MujocoEngine: update_joint_state()
end
MujocoEngine-->>SimInterface: joint state
SimInterface-->>SimModule: positions, velocities, efforts
SimModule->>User: publish JointState
end
User->>SimModule: stop()
SimModule->>SimInterface: disconnect()
SimInterface->>MujocoEngine: disconnect()
alt subprocess mode
MujocoEngine->>ShmWriter: signal_stop()
Subprocess->>ShmReader: should_stop() == true
Subprocess->>Subprocess: exit
MujocoEngine->>Subprocess: terminate/kill
MujocoEngine->>ShmWriter: cleanup()
else threaded mode
MujocoEngine->>MujocoEngine: stop_event.set()
MujocoEngine->>MujocoEngine: join sim_thread
end
|
|
|
||
| def _on_joint_velocity_command(self, msg: JointCommand) -> None: | ||
| with self._command_lock: | ||
| self._pending_velocities = list(msg.positions) |
There was a problem hiding this comment.
uses msg.positions instead of msg.velocities for velocity command
Suggested change
| self._pending_velocities = list(msg.positions) | |
| self._pending_velocities = list(msg.velocities) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
patch to run mujoco as subprocess so viewer works on mac