我写了一个示例订阅者。我想将从 rospy.Subscriber 获得的数据提供给另一个变量,以便我稍后可以在程序中使用它进行处理。目前我可以看到订阅者正在运行,因为当我使用 rospy.loginfo() 函数时,我可以看到正在打印的订阅值。虽然我不知道如何将这些数据存储到另一个变量中。我曾尝试使用赋值运算符“=”将其直接分配给变量,但出现错误。
我尝试使用 rospy.loginfo 编写回调函数来打印订阅对象的位置数据。我已经订阅了 JointState 并且它包含头、位置、速度和努力数组。使用 rospy.loginfo 我可以验证订阅者是否正在订阅。但是当我尝试将它直接分配给变量时,出现错误。
我正在显示来自回调函数的日志信息,如下所示
def callback(data):
rospy.loginfo(data.position)
global listen
listen = rospy.Subscriber("joint_states", JointState,
callback)
rospy.spin()
Run Code Online (Sandbox Code Playgroud)
这很好用。但是当我稍微修改代码以分配订阅的值时,我收到以下错误即
listen1 = rospy.Subscriber("joint_states", JointState,
callback=None)
listen = listen1.position
#rospy.loginfo(listen)
print(listen)
rospy.spin()```
The error is as follows,
```listen = listen1.position
AttributeError: 'Subscriber' object has no attribute 'position'
Run Code Online (Sandbox Code Playgroud)
编辑:这是我在程序中定义的节点,
#rospy.loginfo(msg.data)
global tactile_states
tactile_states = data.data
def joint_callback(data):
#rospy.loginfo(data.position)
global g_joint_states
global g_position
global g_pos1
g_joint_states = data
#for i in len(data.position):
#g_position[i] = data.position[i]
g_position = data.position …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 TensorFlow 顺序模型中实现 CRF 层来解决 NER 问题。我不知道该怎么做。以前,当我实现 CRF 时,我使用 keras 中的 CRF 和 TensorFlow 作为后端,即我在 keras 而不是 TensorFlow 中创建了整个模型,然后通过 CRF 传递整个模型。有效。
But now I want to develop the model in Tensorflow as tensorflow2.0.0 beta already has keras inbuilt in it and I am trying to build a sequential layer and add CRF layer after a bidirectional lstm layer. Although I am not sure how to do that. I have gone through the CRF documentation in tensorflow-addons and it contains different …