back to Index

netrobot

2014-07-19

network robot driver


In [5]:
# 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 [6]:
import time, lcm
from python.forseti2 import piemos_cmd
from python.fearing import xbox_joystick_state
import python.fearing

In [7]:
class NetRobot:
    def __init__(self):
        self.lc=lcm.LCM('udpm://239.255.76.67:7667?ttl=1')
        self.xbs=xbox_joystick_state()
        self.xbs.header = python.fearing.header()
        self.enabled=True
        self.last_left=0
        self.last_right=0
    def enable(self):
        self.enabled=True
        self.cmd(self.last_left, self.last_right)
    def disable(self):
        self.enabled=False
        self.cmd(self.last_left, self.last_right)
    def cmd(self, left, right):
        self.last_left=left
        self.last_right=right
        if self.enabled:
            self.xbs.axes[1]=left
            self.xbs.axes[4]=right
        else:
            self.xbs.axes[1]=0
            self.xbs.axes[4]=0
        self.lc.publish('robot0/cmd', self.xbs.encode())

In [8]:
#NBINCLUDE_STOP

In [9]:
nr=NetRobot()

In [12]:
nr.cmd(1,1)

In [13]:
nr.disable()

In [15]:
nr.enable()

In [16]:
nr.cmd(0,0)

In [ ]: