gpt4 book ai didi

network-programming - 网络表 C++

转载 作者:行者123 更新时间:2023-12-05 07:59:12 25 4
gpt4 key购买 nike

我对 C++ 套接字编程还很陌生。由于我在 FRC 团队中,我需要通过称为“网络表”的接口(interface)在我的应用程序和 Compact RIO 之间进行通信。我需要从我的 C++ 视觉应用程序与我们的 Java 机器人代码进行通信。如何在常规 C++ 中实现 NetworkTables?

最佳答案

这就是我在 python 中所做的,但概念是相同的。目标是根据您在驾驶员站收到的值(传感器数据)移动电机?那么,我该如何完成……数据传输将通过网络表完成

首先,初始化...

from networktables import NetworkTables

# As a client to connect to a robot
NetworkTables.initialize(server='roborio-XXX-frc.local')
  • 创建实例,您将能够访问 NetworkTables 连接、配置设置、监听器并创建表对象,这些对象实际用于发送数据

接下来,

sd = NetworkTables.getTable('SmartDashboard')

sd.putNumber('someNumber', 1234)
otherNumber = sd.getNumber('otherNumber')

在这里,我们与 SmartDashboard 交互并调用两个方法来发送和接收值。

另一个示例,来自 API 文档

#!/usr/bin/env python3
#
# This is a NetworkTables server (eg, the robot or simulator side).
#
# On a real robot, you probably would create an instance of the
# wpilib.SmartDashboard object and use that instead -- but it's really
# just a passthru to the underlying NetworkTable object.
#
# When running, this will continue incrementing the value 'robotTime',
# and the value should be visible to networktables clients such as
# SmartDashboard. To view using the SmartDashboard, you can launch it
# like so:
#
# SmartDashboard.jar ip 127.0.0.1
#

import time
from networktables import NetworkTables

# To see messages from networktables, you must setup logging
import logging

logging.basicConfig(level=logging.DEBUG)

NetworkTables.initialize()
sd = NetworkTables.getTable("SmartDashboard")

i = 0
while True:
print("dsTime:", sd.getNumber("dsTime", -1))

sd.putNumber("robotTime", i)
time.sleep(1)
i += 1

关于network-programming - 网络表 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22292583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com