back to Index
2014-07-20
teleop code
In [1]:
# Cross-notebook include shim
with open("nbinclude.ipynb") as nbinclude_f: # don't rename nbinclude_f
import IPython.nbformat.current
get_ipython().run_cell(IPython.nbformat.current.read(nbinclude_f, 'json').worksheets[0].cells[0].input)
In [2]:
nbinclude("netrobot")
In [3]:
import time, lcm
from python.forseti2 import piemos_cmd
from python.fearing import xbox_joystick_state
In [4]:
class RobotRunner:
def __init__(self):
self.robot=NetRobot()
self.autonomous=False
def handle_joy(self, chan, data):
if not self.autonomous:
msg = xbox_joystick_state.decode(data)
l,r = msg.axes[1], msg.axes[3]
self.robot.cmd(-l,-r)
def handle_piemos(self, channel, data):
msg=piemos_cmd.decode(data)
self.autonomous=msg.auton
if self.autonomous:
self.robot.cmd(-.2, .2)
def lcm_run(self):
lc=lcm.LCM('udpm://239.255.76.67:7667?ttl=1')
sub=lc.subscribe("robot0/joy", self.handle_joy)
sub2=lc.subscribe("piemos0/cmd", self.handle_piemos)
self.running = True
while self.running:
lc.handle()
# for tick in self.ticks:
# tick()
time.sleep(.01)
In [ ]:
rr=RobotRunner()
In [ ]:
rr.lcm_run()
In [ ]: