首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Linux编写的网页实现对机械臂的控制

用Linux编写的网页实现对机械臂的控制
EN

Stack Overflow用户
提问于 2012-03-27 06:12:43
回答 1查看 703关注 0票数 1

首先,我不再是一名学生,目前正在为一位朋友做一件事。我正在制作一个网站,其中有一个机械臂和引爆按钮,将允许用户与机械臂的基本互动的现场视频馈送。

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

我已经完成了maplin机械臂所需的python代码,现在我卡住了,不确定如何将我的python代码与网页界面链接起来?有没有人可以提供我可以编辑和学习的代码?

Python代码

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-27 06:35:52

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

这是一个Python和CGI模块的good tutorial

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9880634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档