-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Launch the ROS demo" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%bash --bg\n", | ||
"trap 'kill $(jobs -p)' EXIT\n", | ||
"xterm -e /bin/bash -l -c \"roslaunch demo.launch\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Create the controller and run it periodically in a thread" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import rospy\n", | ||
"from threading import Thread\n", | ||
"from controller import Controller\n", | ||
"\n", | ||
"rospy.init_node('ns_demo')\n", | ||
"c = Controller()\n", | ||
"\n", | ||
"def worker():\n", | ||
" rate = rospy.Rate(50)\n", | ||
" while not rospy.is_shutdown():\n", | ||
" c.pose_control(c.im_server.target)\n", | ||
" rate.sleep()\n", | ||
" \n", | ||
"t = Thread(target=worker)\n", | ||
"t.start()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Create a list of slider widgets, one for each joint, to chose the default pose" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipywidgets\n", | ||
"from ipywidgets import FloatSlider, Layout, Button, Box\n", | ||
"joint_widgets = [FloatSlider(min = j.min, max = j.max, step = (j.max-j.min) / 100, description = j.name) \\\n", | ||
" for j in c.robot.active_joints]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"React to slider (value) changes by adapting the default joint pose" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def on_sent(event):\n", | ||
" widget = event.owner\n", | ||
" c.preferred_joints[c.joint_msg.name.index(widget.description)] = widget.value\n", | ||
"\n", | ||
"for widget in joint_widgets:\n", | ||
" widget.observe(on_sent, 'value')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Collect all widgets (sliders and buttons) in a form and display them" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"scrolled": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"form = Box(joint_widgets, layout=Layout(\n", | ||
" display='flex',\n", | ||
" flex_flow='column',\n", | ||
" border='solid 2px',\n", | ||
" align_items='stretch',\n", | ||
" width='100%'\n", | ||
"))\n", | ||
"display(form)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"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.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |