jetracer——自动驾驶车项目(teleoperation.ipynb)

文章格式及说明请查看上篇文章:jetracer——自动驾驶车项目(basic_motion.ipynb)

Teleoperation

  • 远程操作

In this example we’ll control the Jetbot remotely with a gamepad controller connected to our web browser machine.

  • 在本例中,我们将使用连接到web浏览器机器上的手柄远程控制Jetbot。手柄的接收器应该连接到jupyterLab网页的设备上去,而不是jetson nano设备上。

Create gamepad controller

  • 创建手柄控制器

The first thing we want to do is create an instance of the Controller widget, which we’ll use to drive our robot. The Controller widget takes a index parameter, which specifies the number of the controller. This is useful in case you have multiple controllers attached, or some gamepads appear as multiple controllers. To determine the index of the controller you’re using,

  • 我们要做的第一件事是创建Controller小部件的实例,我们将使用它来驱动小车。Controller小部件接收一个索引参数,该参数指定控制器的编号。如果你有多个控制器,或者一些游戏手柄显示为多个控制器,这将很有用。为了确定你正在使用的控制器的索引,请使用以下方法。
  1. Visit http://html5gamepad.com.
  2. Press buttons on the gamepad you’re using
  3. Remember the index of the gamepad that is responding to the button presses
  • 1、打开 http://html5gamepad.com 网站。
    2、按下手柄上的按钮。
    3、记住响应按键按压的手柄索引。

Next, we’ll create and display our controller using that index.

  • 接下来,我们将使用该索引创建并显示控制器。
  • http://html5gamepad.com 网站可用于测试手柄数据,一般来说,如果你只连接了一个手柄,其index值一般来说是0,但是也可以是其他,本例中手柄初始状态的值为0。

在这里插入图片描述

  • 在模拟信号键未开启的情况下右摇杆输出值为B0~B3的0或1状态值,左摇杆为AXIS0或AXIS1的模拟值。
  • 在模拟信号开启时左摇杆为AXIS0或AXIS1的模拟值。右摇杆为AXIS2或AXIS5的模拟值。
  • index值在最开头,为0或其他。
# 导入部件库
import ipywidgets.widgets as widgets
​
#创建部件控制器,即手柄控制器,注意手柄的索引改为你要使用的手柄索引
controller = widgets.Controller(index=0)  # replace with index of your controller
​
display(controller)

*运行结果:在这里插入图片描述
Even if the index is correct, you may see the text Connect gamepad and press any button. That’s because the gamepad hasn’t registered with this notebook yet. Press a button and you should see the gamepad widget appear above.

  • 如果索引是正确的,或许你还会看到Connect gamepad and press any button. 文本,因为你的手柄没有在电脑上注册。你可以按任意按钮,这时上面的控制部件就会实时改变其状态。

Connect gamepad controller to robot motors

  • 将手柄和小车的马达连接起来

    Now, even though we’ve connected our gamepad, we haven’t yet attached the controls to our robot! The first, and most simple control we want to attach is the motor control. We’ll connect that to the left and right vertical axes using the dlink function. The dlink function, unlike the link function, allows us to attach a transform between the source and target. Because the controller axes are flipped from what we think is intuitive for the motor control, we’ll use a small lambda function to negate the value.
  • 现在,尽管我们已经连接了游戏手柄,但我们还没有将控制连接到机器人上。首先,最简单的控制是我们想要添加的马达控制。我们将使用dlink函数将其连接到左右垂直轴上。dlink函数,不像link函数,允许我们附加一个转换之间的目标。因为控制器轴是从我们认为的直观的电机控制中翻转的,我们将使用一个小的lambda函数来否定该值。

WARNING: This next cell will move the robot if you touch the gamepad controller axes!
注意:下面的代码将会驱动小车,如果你触碰摇杆的话。

from jetracer.nvidia_racecar import NvidiaRacecar
import traitlets
​
car = NvidiaRacecar()
​
car.throttle_gain = 1
car.steering_offset=-0.085
car.steering = 0
  • 这里是小车基础速度增益,转向,转向偏移设置

controller.axes[0]

left_link = traitlets.dlink((controller.axes[0], 'value'), (car, 'steering'), transform=lambda x: -x)
right_link = traitlets.dlink((controller.axes[2], 'value'), (car, 'throttle'), transform=lambda x: -x)
  • 将手柄控制值链接到小车的转向,速度值。 transform值是函数内部所需值。

Awesome! Our robot should now respond to our gamepad controller movements. Now we want to view the live video feed from the camera!

  • 太棒了!我们的机器人现在应该对我们的手柄控制器的动作做出反应。接下来是视频反馈。
print(car.steering_offset)
-0.085
print(car.steering_gain)
-0.65
print(car.throttle_gain)
0.5
  • 一些参数的输出结果。

猜你喜欢

转载自blog.csdn.net/weixin_44350337/article/details/114499177