gpt4 book ai didi

html - 使用 Linux 编写的网页控制机械臂

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:37 29 4
gpt4 key购买 nike

首先,我不再是学生,目前正在帮 friend 帮忙。我正在制作一个网站,其中有一个机械臂的实时视频源和一个启动按钮,允许用户与机械臂进行基本交互。

我已经设置了网站和实时视频源。我使用闪存媒体编码器和闪存服务器 4.5 确实有 4 秒的延迟。在减少延迟时间方面有什么建议吗?

我已经完成了 maplin 机械臂所需的 python 代码,现在我卡住了,不知道如何将我的 python 代码链接到网页界面?之前做过这件事的任何人都可以提供我可以编辑和学习的代码吗..

Python代码

import usb.core
import usb.util
import sys
import time

# This program is intended to control a robotic arm via USB from Linux
# The code is written in Python by Neil Polwart (c) 2011
# It is a work in progress and will improved!

# locate the device device

dev = usb.core.find(idVendor=0x1267, idProduct=0x0000)

# assigns the device to the handle "dev"
# can check the device is visible to Linux with command line command lsusb
# which should report a device with the above vendor and id codes.

# was it found?

if dev is None:
raise ValueError('Device not found') # if device not found report an error


# set the active configuration

dev.set_configuration()

# as no arguments, the first configuration will be the active one
# note as commands are sent to device as commands not data streams
# no need to define the endpoint

# defines the command packet to send

datapack=0x80,0,0

# change this packet to make different moves.
# first byte defines most of the movements, second byte shoulder rotation, third byte light
# command structure in more detail:
# http://notbrainsurgery.livejournal.com/38622.html?view=93150#t93150

print "requested move",datapack # reports the requested movement to the user

# send the command

bytesout=dev.ctrl_transfer(0x40, 6, 0x100, 0, datapack, 1000)

# outputs the command to the USB device, using the ctrl_transfer method
# 0x40, 6, 0x100, 0 defines the details of the write - bRequestType, bRequest, wValue, wIndex
# datapack is our command (3 bytes)
# the final value is a timeout (in ms) which is optional
# bytesout = the number of bytes written (i.e. 3 if successful)

print "Written :",bytesout,"bytes" # confirm to user that data was sent OK

# wait for a defined period

time.sleep(1) # waits for 1 second whilst motors move.

# now STOP the motors

datapack=0,0,0

bytesout=dev.ctrl_transfer(0x40, 6, 0x100, 0, datapack, 1000)

if bytesout == 3: print "Motors stopped"

所以我需要找到一种通过网站界面编辑数据包行的方法。任何帮助表示赞赏!我使用的是 Windows 7 安装程序,但可以访问 vmware

最佳答案

我会用 mod_python 设置一个 Apache 服务器并创建一个处理程序来导入您的脚本并运行必要的代码。您可以在 JavaScript 中设置 AJAX 脚本(带或不带 jQuery )。每次要运行 Python 脚本时,都需要向服务器发出请求。您可以根据需要通过 HTTP 来回传递任何信息。


这是一个 good tutorial用于 Python 和 CGI​​ 模块。

关于html - 使用 Linux 编写的网页控制机械臂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9880634/

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