Jetbot-AI机器人教程-WEB网页控制
Jetbot-AI机器人教程-WEB网页控制
说明:
- 介绍如何通过web界面控制小车
步骤:
- 基本界面:
访问http://<jetbot_ip_address>:8888连接到您的机器人
使用默认密码jetbot登录
导航到~/Notebooks/basic_motion/
打开basic_motion.ipynb文件
需要确保JetBot小车有足够的空间移动
点击菜单栏Run -> Run the selected cells and advance,或者点击运行快捷图标▶来运行单段程序
运行下面语句时,小车会向左转圈。如果小车没有正常左转,可能是接线接错了,需要重新检查接线是否正确
robot.left(speed=0.3)
- 运行下面这段程序后,会输出左右两条滑条,拖动滑条可以改变左右点击的转速
import ipywidgets.widgets as widgets
from IPython.display import display
#create two sliders with range [-1.0, 1.0]
left_slider = widgets.FloatSlider(description='left', min=-1.0, max=1.0, step=0.01, orientation='vertical')
right_slider = widgets.FloatSlider(description='right', min=-1.0, max=1.0, step=0.01, orientation='vertical')
# create a horizontal box container to place the sliders next to eachother
slider_container = widgets.HBox([left_slider, right_slider])
# display the container in this cell's output
display(slider_container)
- 运行下面代码之后,可以通过网页按键来控制小车的前后左右移动。通过右键该段代码->Create New View for Output 将输出窗口作为新页面打开
def stop(change):
robot.stop()
def step_forward(change):
robot.forward(0.4)
time.sleep(0.5)
robot.stop()
def step_backward(change):
robot.forward(0.4)
time.sleep(0.5)
robot.stop()
def step_left(change):
robot.forward(0.4)
time.sleep(0.5)
robot.stop()
def step_right(change):
robot.forward(0.4)
time.sleep(0.5)
robot.stop()
# link buttons to actions
stop_button.on_click(stop)
forward_button.on_click(step_forward)
backward_button.on_click(step_backward)
left_button.on_click(step_left)
right_button.on_click(step_right)
- 下面代码通过“心跳”来保持小车的正常工作,拖动滑条降低心跳频率后小车会停止转动
from jetbot import Heartbeat
heartbeat = Heartbeat()
# this function will be called when heartbeat 'alive' status changes
def handle_heartbeat_status(change):
if change['new'] == Heartbeat.Status.dead:
robot.stop()
heartbeat.observe(handle_heartbeat_status, names='status')
period_slider = widgets.FloatSlider(description='period', min=0.001, max=0.5, step=0.01, value=0.5)
traitlets.dlink((period_slider, 'value'), (heartbeat, 'period'))
display(period_slider, heartbeat.pulseout)
演示视频
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号