Skip to content

Commit

Permalink
added mujoco experiement and started refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
manx52 committed Jul 26, 2024
1 parent e381892 commit 9094ddf
Show file tree
Hide file tree
Showing 79 changed files with 510 additions and 285 deletions.
17 changes: 17 additions & 0 deletions .idea/jupyter-settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion soccer_common/src/soccer_common/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@


class Camera:

# TODO maybe put into a common percpetion
# TODO also could be split up into different files too many things
HORIZONTAL_FOV = 1.39626

def __init__(self):
# TODO why does this need pose shouldnt all the calcualtions be in the robots relative frame and
# then transformed into the world frame that would make it a lot less relient on
# knowledge of its global position
self.pose = Transformation()
self.camera_info = None
self.horizontalFOV = Camera.HORIZONTAL_FOV
Expand All @@ -34,7 +38,9 @@ def reset_position(self, from_world_frame=False, camera_frame="/camera", skip_if
trans = [0, 0, 0]
rot = [0, 0, 0, 1]
self.pose = Transformation(trans, rot)
# TODO put in its own ros file
"""
Resets the position of the camera, it uses a series of methods that fall back on each other to get the location of the camera
:param from_world_frame: If this is set to true, the camera position transformation will be from the world instead of the robot odom frame
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
""
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-26T20:27:26.357513Z",
"start_time": "2024-07-26T20:27:26.339991Z"
}
},
"cell_type": "code",
"source": [
"import mujoco\n",
"import mediapy as media\n",
"from IPython.display import clear_output\n",
"import matplotlib.pyplot as plt\n",
"\n",
"chaotic_pendulum = \"\"\"\n",
"<mujoco>\n",
" <option timestep=\".001\">\n",
" <flag energy=\"enable\" contact=\"disable\"/>\n",
" </option>\n",
"\n",
" <default>\n",
" <joint type=\"hinge\" axis=\"0 -1 0\"/>\n",
" <geom type=\"capsule\" size=\".02\"/>\n",
" </default>\n",
"\n",
" <worldbody>\n",
" <light pos=\"0 -.4 1\"/>\n",
" <camera name=\"fixed\" pos=\"0 -1 0\" xyaxes=\"1 0 0 0 0 1\"/>\n",
" <body name=\"0\" pos=\"0 0 .2\">\n",
" <joint name=\"root\"/>\n",
" <geom fromto=\"-.2 0 0 .2 0 0\" rgba=\"1 1 0 1\"/>\n",
" <geom fromto=\"0 0 0 0 0 -.25\" rgba=\"1 1 0 1\"/>\n",
" <body name=\"1\" pos=\"-.2 0 0\">\n",
" <joint/>\n",
" <geom fromto=\"0 0 0 0 0 -.2\" rgba=\"1 0 0 1\"/>\n",
" </body>\n",
" <body name=\"2\" pos=\".2 0 0\">\n",
" <joint/>\n",
" <geom fromto=\"0 0 0 0 0 -.2\" rgba=\"0 1 0 1\"/>\n",
" </body>\n",
" <body name=\"3\" pos=\"0 0 -.25\">\n",
" <joint/>\n",
" <geom fromto=\"0 0 0 0 0 -.2\" rgba=\"0 0 1 1\"/>\n",
" </body>\n",
" </body>\n",
" </worldbody>\n",
"</mujoco>\n",
"\"\"\"\n",
"model = mujoco.MjModel.from_xml_string(chaotic_pendulum)\n",
"data = mujoco.MjData(model)\n",
"height = 480\n",
"width = 640\n",
"\n",
"with mujoco.Renderer(model, height, width) as renderer:\n",
" mujoco.mj_forward(model, data)\n",
" renderer.update_scene(data, camera=\"fixed\")\n",
"\n",
" media.show_image(renderer.render())\n",
" "
],
"id": "d2325b549cd7d10e",
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'mujoco'",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mModuleNotFoundError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[3], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mmujoco\u001B[39;00m\n\u001B[1;32m 2\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mmediapy\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m \u001B[38;5;21;01mmedia\u001B[39;00m\n\u001B[1;32m 3\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mIPython\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mdisplay\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m clear_output\n",
"\u001B[0;31mModuleNotFoundError\u001B[0m: No module named 'mujoco'"
]
}
],
"execution_count": 3
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-26T20:27:27.341789Z",
"start_time": "2024-07-26T20:27:27.340199Z"
}
},
"cell_type": "code",
"source": "",
"id": "a1e4e0175c70e866",
"outputs": [],
"execution_count": 3
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-26T20:27:27.943871Z",
"start_time": "2024-07-26T20:27:27.942200Z"
}
},
"cell_type": "code",
"source": "",
"id": "48cd10deb5af0b86",
"outputs": [],
"execution_count": 3
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-26T20:27:28.142440Z",
"start_time": "2024-07-26T20:27:28.138875Z"
}
},
"cell_type": "code",
"source": "",
"id": "1f98341c9c2caf8b",
"outputs": [],
"execution_count": 3
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "c7736f9160249cc"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 9094ddf

Please sign in to comment.