0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

怎样用ArduinoUNO和Wekinator控制伺服电机

454398 来源:工程师吴畏 2019-08-03 09:46 次阅读

所需硬件

Arduino UNO

2伺服电机

面包板

跳线

必需的软件

Wekinator

Arduino IDE

Wekinator控制的伺服电机电路图

首先连接每个伺服上的红线连接到Arduino的5V引脚。然后将每个伺服的黑线连接到Arduino的地线。最后,将其中一个伺服电机的黄色线连接到Arduino上的引脚8,将黄色线从另一个伺服器连接到引脚9.

通过Wekinator控制伺服系统的电路图

如何在Arduino IDE中运行Wekinator

将本帖末尾提供的Arduino专用代码粘贴到Arduino的IDE中并上传。

然后你需要从Wekinator下载草图文件快速演练页面。

下载演练页面上的屏幕鼠标控制示例。解压缩文件并在处理中运行草图。该草图为Wekinator提供输入。您需要另一个输出部分的草图,您可以在本文末尾找到它。将该代码粘贴到处理窗口并运行它 - 两个处理输出窗口应如下所示:

处理Wekinator中的输出窗口

打开Wekinator并按如下所示更新设置:

将输入窗口设置为2

将输出窗口设置为2

将类型设置为自定义

更新设置后,单击“配置”。

在Wekinator中创建新项目窗口。

单击“配置”后,将打开“自定义输出类型”窗口。在此窗口中,按如下方式调整设置:

在Wekinator中自定义输出类型窗口。

拖动处理中的绿框窗口到左侧中心并将Wekinator窗口中的设置调整为下面显示的值,然后短暂开始和停止录制。

将处理窗口中的绿色框移动到屏幕右侧的中心,并调整Wekinator窗口中的设置,如下所示。再一次,短暂地开始和停止录制

接下来,将处理窗口中的绿框拖到窗口的中央顶部区域并调整设置在下面的Wekinator窗口中显示的那些。再次,快速开始和停止录制。

最后,将处理窗口中的绿色框拖到窗口的底部中心,并将设置调整为反映Wekinator窗口中显示的那些。最后一次,快速开始和停止录制。

单击“训练”按钮,然后选择“运行”。在处理窗口中拖动绿色框时,连接到Arduino的伺服器将相应移动。

处理代码(Wekinator的输出)

import vsync.*; // Importing the library that will help us in sending and receiving the values from the Arduino

import processing.serial.*; // Importing the serial library

// Below libraries will connect and send, receive the values from Wekinator

import oscP5.*;

import netP5.*;

// Creating the instances

OscP5 oscP5;

NetAddress dest;

ValueSender sender;

// These variables will be synchronized with the Arduino and they should be same on the Arduino side.

public int output;

public int output1;

void setup()

{

// Starting the serial communication, the baudrate and the com port should be same as on the Arduino side.

Serial serial = new Serial(this, “COM10”, 19200);

sender = new ValueSender(this, serial);

// Synchronizing the variables as on the Arduino side. The order should be same.

sender.observe(“output”);

sender.observe(“output1”);

// Starting the communication with Wekinator. listen on port 12000, return messages on port 6448

oscP5 = new OscP5(this, 12000);

dest = new NetAddress(“127.0.0.1”, 6448);

}

// Recieve OSC messages from Wekinator

void oscEvent(OscMessage theOscMessage) {

if (theOscMessage.checkAddrPattern(“/wek/outputs”) == true) {

// Receiving the output from Wekinator

float value = theOscMessage.get(0).floatValue(); // First output

float val = theOscMessage.get(1).floatValue(); // Second output

// Converting the output to int type

output = int(value);

output1 = int(val);

}

}

void draw()

{

// Nothing to be drawn for this example

}

Weoulator控制的舵机的Arduino代码

#include // Including the library that will help us in receiving and sending the values from processing

#include // Including the servo library

ValueReceiver《2》 receiver; /*Creating the receiver that will receive up to 2 values.

Put the number of values to synchronize in the brackets */

/* The below two variables will be synchronized in the processing

and they should be same on both sides. */

int output;

int output1;

// Creating the instances

Servo myservo;

Servo myservo1;

void setup()

{

/* Starting the serial communication because we are communicating with the

Arduino through serial. The baudrate should be same as on the processing side. */

Serial.begin(19200);

// Initializing the servo pins

myservo.attach(8);

myservo1.attach(9);

// Synchronizing the variables with the processing. The variables must be int type.

receiver.observe(output);

receiver.observe(output1);

}

void loop()

{

// Receiving the output from the processing.

receiver.sync();

// Check for the info we‘re looking for from Processing

if (output 《 180) {

myservo.write(output);

}

if (output1 《180)

{

myservo1.write(output1);

}

}

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 伺服电机
    +关注

    关注

    82

    文章

    1837

    浏览量

    56199
  • Arduino
    +关注

    关注

    184

    文章

    6425

    浏览量

    184775
收藏 人收藏

    评论

    相关推荐

    伺服电机的三种控制方式 如何确定选择伺服电机控制方式?

    伺服电机的三种控制方式 如何确定选择伺服电机控制方式? 伺服
    的头像 发表于 12-26 14:02 732次阅读

    怎样验证防爆伺服电机是否过冲呢?

    怎样验证防爆伺服电机是否过冲呢? 验证防爆伺服电机是否过冲是非常重要的,因为过冲可能导致设备损坏、事故发生,甚至危及人员的生命安全。下面将详
    的头像 发表于 12-25 11:47 348次阅读

    怎样用ADAU1761设计DRC的压缩/扩展?

    请问怎样用ADAU1761设计DRC的压缩/扩展。我在SigmaStudio 4.5的模块中只找到RMS。如果ADAU1761设计DRC要怎样
    发表于 11-28 06:41

    怎样用32单片机测电压?

    怎样用32单片机测电压
    发表于 10-31 07:09

    总线伺服电机的回零控制方法

    通过总线控制伺服电机时,如何进行回零(寻参考点)控制?这里就CANOPEN伺服电机的回零
    的头像 发表于 10-23 11:42 1819次阅读
    总线<b class='flag-5'>伺服</b><b class='flag-5'>电机</b>的回零<b class='flag-5'>控制</b>方法

    PLC中怎样用X和Y两个轴走出直线轨迹?

    PLC中怎样用X和Y两个轴走出直线轨迹呢?那么这两个轴需要配合成速度成线性比例,位置和速度应该如何云运算呢?
    发表于 09-12 09:58 353次阅读
    PLC中<b class='flag-5'>怎样用</b>X和Y两个轴走出直线轨迹?

    PLC怎么控制伺服电机

    在回答这个问题之前,首先要清楚伺服电机的用途,相对于普通的电机来说,伺服电机主要用于精确定位,因此大家通常所说的
    发表于 09-08 11:22 826次阅读

    什么是伺服电机伺服电机的类型有哪些?

    什么是伺服电机伺服是一种电磁装置,利用负反馈机制将电信号转换为受控运动。基本上,伺服系统的行为类似于执行器,提供对速度、加速度和线性或角度位置的精确
    的头像 发表于 08-30 08:08 1887次阅读
    什么是<b class='flag-5'>伺服</b><b class='flag-5'>电机</b>?<b class='flag-5'>伺服</b><b class='flag-5'>电机</b>的类型有哪些?

    PLC是怎么控制伺服电机的?

    在回答这个问题之前,首先要清楚伺服电机的用途,相对于普通的电机来说,伺服电机主要用于精确定位,因此大家通常所说的
    发表于 08-09 09:25 671次阅读

    浅谈伺服电机的三种控制方式

    伺服电机控制方式有脉冲、模拟量和通讯控制这三种,在不同的应用场景下,该如何确定选择伺服电机
    发表于 07-26 09:22 1067次阅读
    浅谈<b class='flag-5'>伺服</b><b class='flag-5'>电机</b>的三种<b class='flag-5'>控制</b>方式

    如何使用单片机控制伺服电机

    伺服电机是我们常用的一种电机,在本文的案例中,将学习如何使用单片机控制伺服电机,案例以PIC16
    的头像 发表于 07-06 10:53 3174次阅读
    如何使用单片机<b class='flag-5'>控制</b><b class='flag-5'>伺服</b><b class='flag-5'>电机</b>?

    如何使用IC555控制伺服电机的方向

    伺服电机是一种可以精确控制角度方向的电子设备。当涉及到以精确角度移动或旋转物体时,伺服电机是此类应用的最佳选择。它由一个简单的直流
    发表于 06-18 09:58 466次阅读
    如何使用IC555<b class='flag-5'>控制</b><b class='flag-5'>伺服</b><b class='flag-5'>电机</b>的方向

    怎样用FPGA实现FSK调制解调呢?

    最近想做这方面的,怎样用FPGA实现FSK调制解调?但是我一点头绪都没有,哪位高手帮帮忙,讲解一下什么的
    发表于 05-08 17:34

    使用Arduino控制伺服电机

    伺服电机是一个闭环系统,它使用位置反馈来控制其运动和最终位置。伺服电机有多种类型,其主要特点是能够精确
    发表于 05-06 10:08 2次下载
    使用Arduino<b class='flag-5'>控制</b><b class='flag-5'>伺服</b><b class='flag-5'>电机</b>

    PLC如何控制伺服电机?如何设计伺服系统?

    在回答这个问题之前,首先要清楚伺服电机的用途,相对于普通的电机来说,伺服电机主要用于精确定位,因此大家通常所说的
    的头像 发表于 04-27 17:34 1220次阅读
    PLC如何<b class='flag-5'>控制</b><b class='flag-5'>伺服</b><b class='flag-5'>电机</b>?如何设计<b class='flag-5'>伺服</b>系统?