0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
电子发烧友
开通电子发烧友VIP会员 尊享10大特权
海量资料免费下载
精品直播免费看
优质内容免费畅学
课程9折专享价
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

怎樣用ArduinoUNO和Wekinator控制伺服電機(jī)

454398 ? 來源:工程師吳畏 ? 2019-08-03 09:46 ? 次閱讀

所需硬件

Arduino UNO

2伺服電機(jī)

面包板

跳線

必需的軟件

Wekinator

Arduino IDE

Wekinator控制的伺服電機(jī)電路圖

首先連接每個(gè)伺服上的紅線連接到Arduino的5V引腳。然后將每個(gè)伺服的黑線連接到Arduino的地線。最后,將其中一個(gè)伺服電機(jī)的黃色線連接到Arduino上的引腳8,將黃色線從另一個(gè)伺服器連接到引腳9.

通過Wekinator控制伺服系統(tǒng)的電路圖

如何在Arduino IDE中運(yùn)行Wekinator

將本帖末尾提供的Arduino專用代碼粘貼到Arduino的IDE中并上傳。

然后你需要從Wekinator下載草圖文件快速演練頁(yè)面。

下載演練頁(yè)面上的屏幕鼠標(biāo)控制示例。解壓縮文件并在處理中運(yùn)行草圖。該草圖為Wekinator提供輸入。您需要另一個(gè)輸出部分的草圖,您可以在本文末尾找到它。將該代碼粘貼到處理窗口并運(yùn)行它 - 兩個(gè)處理輸出窗口應(yīng)如下所示:

處理Wekinator中的輸出窗口

打開Wekinator并按如下所示更新設(shè)置:

將輸入窗口設(shè)置為2

將輸出窗口設(shè)置為2

將類型設(shè)置為自定義

更新設(shè)置后,單擊“配置”。

在Wekinator中創(chuàng)建新項(xiàng)目窗口。

單擊“配置”后,將打開“自定義輸出類型”窗口。在此窗口中,按如下方式調(diào)整設(shè)置:

在Wekinator中自定義輸出類型窗口。

拖動(dòng)處理中的綠框窗口到左側(cè)中心并將Wekinator窗口中的設(shè)置調(diào)整為下面顯示的值,然后短暫開始和停止錄制。

將處理窗口中的綠色框移動(dòng)到屏幕右側(cè)的中心,并調(diào)整Wekinator窗口中的設(shè)置,如下所示。再一次,短暫地開始和停止錄制

接下來,將處理窗口中的綠框拖到窗口的中央頂部區(qū)域并調(diào)整設(shè)置在下面的Wekinator窗口中顯示的那些。再次,快速開始和停止錄制。

最后,將處理窗口中的綠色框拖到窗口的底部中心,并將設(shè)置調(diào)整為反映Wekinator窗口中顯示的那些。最后一次,快速開始和停止錄制。

單擊“訓(xùn)練”按鈕,然后選擇“運(yùn)行”。在處理窗口中拖動(dòng)綠色框時(shí),連接到Arduino的伺服器將相應(yīng)移動(dòng)。

處理代碼(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控制的舵機(jī)的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);

}

}

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 伺服電機(jī)
    +關(guān)注

    關(guān)注

    85

    文章

    2061

    瀏覽量

    58334
  • Arduino
    +關(guān)注

    關(guān)注

    188

    文章

    6477

    瀏覽量

    188114
收藏 0人收藏

    評(píng)論

    相關(guān)推薦

    其利天下技術(shù)·伺服電機(jī)編碼器的作用及工作原理·低壓伺服電機(jī)驅(qū)動(dòng)方案開發(fā)

    電機(jī)系統(tǒng)中起著至關(guān)重要的作用,是實(shí)現(xiàn)高效、穩(wěn)定和精確控制的核心組件。編碼器的作用是什么呢?它的工作原理又是怎樣的?其利天下·伺服電機(jī)驅(qū)動(dòng)方案
    的頭像 發(fā)表于 11-02 10:38 ?462次閱讀
    其利天下技術(shù)·<b class='flag-5'>伺服</b><b class='flag-5'>電機(jī)</b>編碼器的作用及工作原理·低壓<b class='flag-5'>伺服</b><b class='flag-5'>電機(jī)</b>驅(qū)動(dòng)方案開發(fā)

    伺服電機(jī)原理及控制應(yīng)用

    伺服電機(jī)(Servo Motor)是一種高精度、高性能的電動(dòng)機(jī)系統(tǒng),廣泛應(yīng)用于需要精確控制位置、速度和加速度的場(chǎng)合。 一、伺服電機(jī)的工作原理
    的頭像 發(fā)表于 10-22 16:58 ?1433次閱讀

    伺服電機(jī)有什么,伺服電機(jī)可以當(dāng)普通電機(jī)

    一、伺服電機(jī)的作用與特點(diǎn) 伺服電機(jī)(Servo motor),作為伺服系統(tǒng)中的關(guān)鍵組件,扮演著控制
    的頭像 發(fā)表于 10-22 16:16 ?751次閱讀

    什么是伺服電機(jī)伺服電機(jī)的工作原理是什么?

    伺服電機(jī)是一種高精度的電機(jī),廣泛應(yīng)用于自動(dòng)化控制、機(jī)器人、精密機(jī)械等領(lǐng)域。它能夠根據(jù)輸入的控制信號(hào),精確地
    的頭像 發(fā)表于 10-22 10:58 ?963次閱讀

    步進(jìn)電機(jī)伺服控制系統(tǒng)的作用

    步進(jìn)電機(jī)伺服控制系統(tǒng)是一種精密的電機(jī)控制系統(tǒng),它通過精確控制
    的頭像 發(fā)表于 09-04 09:46 ?839次閱讀

    PLSY指令怎樣控制伺服正反轉(zhuǎn)

    PLSY指令(PLC中的脈沖輸出指令)通常用于控制伺服電機(jī)的正反轉(zhuǎn)和速度。 1. 伺服電機(jī)概述 伺服
    的頭像 發(fā)表于 08-19 14:51 ?2190次閱讀

    伺服電機(jī)怎么選型和計(jì)算(伺服電機(jī)電流環(huán)控制原理)

    在現(xiàn)代工業(yè)自動(dòng)化領(lǐng)域,伺服電機(jī)扮演著精密控制設(shè)備中不可或缺的角色。其卓越的精度和響應(yīng)速度是實(shí)現(xiàn)精密控制的關(guān)鍵因素。因此,正確的選型和精確的計(jì)算對(duì)于保障設(shè)備的性能和系統(tǒng)的穩(wěn)定性具有決定性
    的頭像 發(fā)表于 08-02 08:37 ?618次閱讀
    <b class='flag-5'>伺服</b><b class='flag-5'>電機(jī)</b>怎么選型和計(jì)算(<b class='flag-5'>伺服</b><b class='flag-5'>電機(jī)</b>電流環(huán)<b class='flag-5'>控制</b>原理)

    伺服電機(jī)也是脈沖控制嗎為什么

    伺服電機(jī)是一種高精度、高響應(yīng)速度的電機(jī),廣泛應(yīng)用于工業(yè)自動(dòng)化、機(jī)器人、航空航天等領(lǐng)域。伺服電機(jī)控制
    的頭像 發(fā)表于 07-14 10:37 ?1090次閱讀

    伺服驅(qū)動(dòng)器對(duì)伺服電機(jī)控制要求

    伺服驅(qū)動(dòng)器對(duì)伺服電機(jī)控制要求是一個(gè)復(fù)雜而深入的話題。以下是關(guān)于伺服驅(qū)動(dòng)器對(duì)伺服
    的頭像 發(fā)表于 06-14 15:24 ?940次閱讀

    運(yùn)動(dòng)控制伺服電機(jī)如何控制

    運(yùn)動(dòng)控制伺服電機(jī)控制是現(xiàn)代工業(yè)自動(dòng)化領(lǐng)域中一項(xiàng)重要的技術(shù),它涉及到運(yùn)動(dòng)控制卡、伺服
    的頭像 發(fā)表于 06-12 14:13 ?1083次閱讀

    plc控制伺服電機(jī)的指令有哪些

    PLC(可編程邏輯控制器)是一種廣泛應(yīng)用于工業(yè)自動(dòng)化領(lǐng)域的控制設(shè)備。伺服電機(jī)作為執(zhí)行元件,可以通過PLC進(jìn)行精確控制。以下是關(guān)于PLC
    的頭像 發(fā)表于 06-12 11:39 ?2759次閱讀

    伺服電機(jī)可以當(dāng)普通電機(jī)

    伺服電機(jī)和普通電機(jī)在很多方面都有所不同,因此不能簡(jiǎn)單地將伺服電機(jī)當(dāng)作普通電機(jī)使用。
    的頭像 發(fā)表于 06-12 10:05 ?1694次閱讀

    伺服電機(jī)最簡(jiǎn)單控制方法是什么

    伺服電機(jī)是一種高精度、高響應(yīng)速度的電機(jī),廣泛應(yīng)用于工業(yè)自動(dòng)化、機(jī)器人、航空航天等領(lǐng)域。伺服電機(jī)控制
    的頭像 發(fā)表于 06-05 15:49 ?951次閱讀

    伺服電機(jī)控制器怎么調(diào)參數(shù)

    伺服電機(jī)控制器參數(shù)調(diào)整是確保伺服系統(tǒng)正常運(yùn)行和達(dá)到預(yù)期性能的關(guān)鍵步驟。本文將詳細(xì)介紹伺服電機(jī)
    的頭像 發(fā)表于 06-05 15:47 ?2381次閱讀

    stm32f100怎樣用重映射功能?

    的是stm32f100c8t6b芯片,現(xiàn)在想用將PB1映射為TIM1_CH3N,在調(diào)用GPIO_PinAFConfig(GPIOB,GPIO_PinSource1,GPIO_AF_TIM1)時(shí), GPIO_PinAFConfig和GPIO_AF_TIM1都沒定義,stm32f100
    發(fā)表于 05-07 06:06

    電子發(fā)燒友

    中國(guó)電子工程師最喜歡的網(wǎng)站

    • 2931785位工程師會(huì)員交流學(xué)習(xí)
    • 獲取您個(gè)性化的科技前沿技術(shù)信息
    • 參加活動(dòng)獲取豐厚的禮品