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

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

3天内不再提示

如何使用双极电机创建3点轴机械臂

454398 来源:wv 2019-10-21 17:39 次阅读

步骤1:原理图和组件列表

如何使用双极电机创建3点轴机械臂

这是我们在此项目中使用的完整原理图和可用组件的概述。

包含的组件如下:

Berger Lahr双极步进电机(已安装在机械臂上)

Arduino UNO

PlayStation2游戏杆

Cyber 310机械臂

超声波接近传感器HC-SR04

面包板

PlayStation2 RC直升机的振动电机和转子

EasyDriver 4.4步进电机驱动器

5V AC/DC电源

我们主要选择这些组件是因为它们很容易为我们使用。我们还认为,与同班同学相比,使用更大的机械臂会很有趣。尽管我们意识到了这一点,但我们的野心超出了我们的能力。

步骤2:构造操作设备

我们焊接并连接了几部分印刷品和许多电线,以便获得适当的运行电路来控制我们的机械臂。

设计本身主要基于尽管在实际施工过程中进行了一些修改,但本节上面概述的概述中没有提及。

步骤3:对其中的一些进行了实现,以实现超声传感器。

步骤3:机器人手臂的测试代码

下面包含的机械手测试代码

我们使用这段代码来测试机械臂是否在实际工作,因为我们很难对完整代码(包含在步骤6中)做出反应。该代码的某些部分已过时,因为实际设备中未使用它。

#define step_pin 6 // Pin 6 connected to Steps pin on EasyDriver

#define dir_pin 7 // Pin 7 connected to Direction pin

//#define MS1 5 // Pin 5 connected to MS1 pin

//#define MS2 4 // Pin 4 connected to MS2 pin

#define SLEEP 10 // Pin 10 connected to SLEEP pin

#define X_pin A0 // Pin A0 connected to joystick x axis

int direction; // Variable to set Rotation (CW-CCW) of the motor

int steps = 1025; // Assumes the belt clip is in the Middle

void setup() {

// pinMode(MS1, OUTPUT);

// pinMode(MS2, OUTPUT);

pinMode(dir_pin, OUTPUT);

pinMode(step_pin, OUTPUT);

pinMode(SLEEP, OUTPUT);

digitalWrite(SLEEP, HIGH); // Wake up EasyDriver

delay(5); // Wait for EasyDriver wake up

/* Configure type of Steps on EasyDriver:

// MS1 MS2

//

// LOW LOW = Full Step //

// HIGH LOW = Half Step //

// LOW HIGH = A quarter of Step //

// HIGH HIGH = An eighth of Step //

*/

// digitalWrite(MS1, LOW); // Configures to Full Steps

// digitalWrite(MS2, LOW); // Configures to Full Steps

}

void loop() {

while (analogRead(X_pin) 》= 0 && analogRead(X_pin) 《= 100) {

if (steps 》 0) {

digitalWrite(dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps--;

}

}

while (analogRead(X_pin) 》 100 && analogRead(X_pin) 《= 400) {

if (steps 《 512) {

digitalWrite(dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps++;

}

if (steps 》 512) {

digitalWrite(dir_pin, HIGH);

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps--;

}

}

while (analogRead(X_pin) 》 401 && analogRead(X_pin) 《= 600) {

if (steps 《 1025) {

digitalWrite(dir_pin, HIGH);

digitalWrite(step_pin, HIGH );

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps++;

}

if (steps 》 1025) {

digitalWrite(dir_pin, HIGH);

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps--;

}

}

while (analogRead(X_pin) 》 601 && analogRead(X_pin) 《= 900) {

if (steps 《 1535) {

digitalWrite(dir_pin, HIGH);

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps++;

}

if (steps 》 1535) {

digitalWrite(dir_pin, HIGH);

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps--;

}

}

while (analogRead(X_pin) 》 900 && analogRead(X_pin) 《= 1024) {

if (steps 《 2050) {

digitalWrite(dir_pin, HIGH);

digitalWrite(step_pin, HIGH);

delay(1);

digitalWrite(step_pin, LOW);

delay(1);

steps++;

}

}

}

步骤4:传感器代码

包括超声波传感器的代码

为传感器选择的代码经过构造,以便当风扇在以下范围内注册对象时风扇将运行。距回波点10至20厘米。

尽管我们同时更改了引脚和范围,但物理构造仍基于上面的示意图。

/*

HC-SR04 Ping distance sensor:

VCC to arduino 5v

GND to arduino GND

Echo to Arduino pin 8

Trig to Arduino pin 9

*/

#define echoPin 11 // Echo Pin

#define trigPin 12 // Trigger Pin

#define LEDPin 8 // Onboard LED

int maximumRange = 20; // Maximum range needed

int minimumRange = 10; // Minimum range needed

long duration, distance; // Duration used to calculate distance

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)

}

void loop() {

/* The following trigPin/echoPin cycle is used to determine the

distance of the nearest object by bouncing soundwaves off of it. */

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.

distance = duration/58.2;

if (distance 》= maximumRange || distance 《= minimumRange){

/* Send a negative number to computer and Turn LED ON

to indicate “out of range” */

Serial.println(“fuckboy”);

digitalWrite(LEDPin, LOW);

}

else {

/* Send the distance to the computer using Serial protocol, and

turn LED OFF to indicate successful reading. */

Serial.println(distance);

digitalWrite(LEDPin, HIGH);

}

//Delay 50ms before next reading.

delay(50); }

步骤5:一点点视频(和麻烦)

上面的精选视频显示了我们最大的问题之一。

我们根本没有足够的视频电压功率来运行机械臂本身。机器肯定在接收信号,但是它很小,甚至不能转动旋钮来驱动手臂的轴点。

主要问题集中在为机器人提供正确的电压。电机,由于最大输入功率之间的差异,您可以放心地将其输入到Arduino和使实际电机本身正常运行所需的功率中。

步骤6:完整的主控制代码

下面包含了机械手臂的完整代码。

我们使用的代码存在一些问题,但是由于我们在电压功率方面也存在一些问题,如步骤5所述,我们很难对所有这些进行分类。应该注意的是,此部分代码不包含传感器的代码。

#ifndef _stepLib_h_

#define _stepLib_h_

#include “Arduino.h”

// define our stepper class

class stepMotor {

public:

stepMotor(byte stepPin, byte dirPin); // our stepper object with variables stepPin and dirPin

void step(unsigned int stepFreq); // our stepping function which takes as an input our stepping frequency

private:

unsigned long _time; // current time

unsigned long _lastStepTime; // time at which we last stepped

unsigned long _stepPeriod; // time between a half period - this is the same as our delay(X) of part 1

byte _stepPin;

byte _dirPin;

boolean _stepCycle; // defines if we are on the HIGH or LOW side of our step cycle

};

#endif

#include “Arduino.h”

#include “stepLib.h”

// used for declaring our motor and initializing it

stepMotor::stepMotor(byte stepPin, byte dirPin) {

_stepPin = stepPin;

_dirPin = dirPin;

// define our digital pins as output

pinMode(_stepPin, OUTPUT);

pinMode(_dirPin, OUTPUT);

// initialize our digital pins to LOW

digitalWrite(_stepPin, LOW);

digitalWrite(_dirPin, LOW);

_stepCycle = false; // this keeps track of which end of the step cycle we are on: high or low

}

// function responsible for driving our digital pins high/low at the proper frequency

// input is the stepping frequency

void stepMotor::step(unsigned int stepFreq) {

_time = micros(); // get the current time

_stepPeriod = 1000000 / stepFreq; // get our step period (in micro-seconds) from the user given step frequency; we lose a bit of accuracy here since we‘ve defined _stepPeriod as an unsigned long instead of a float, but that’s ok.。.

// if the proper amount of time has passed, let‘s go ahead and proceed to the next half of our step cycle

if (_time 》= _lastStepTime + _stepPeriod) {

digitalWrite(_stepPin, _stepCycle == true); // a compact way of writing either HIGH/LOW to our step pin based on where we are on our step cycle

_stepCycle = !_stepCycle; // this simply flips our Boolean

_lastStepTime = _time; // update the time we last stepped

}

}

#include “stepLib.h”

// define a constant value named stepPin and assign the value 8 to it - this value will not change during our code

// this assumes digital pin 8 of your Arduino is attached to the step input of your driver

#define stepPin 9

// define a constant value named dirPin and assign the value 8 to it - this value will not change during our code

// this assumes digital pin 9 of your Arduino is attached to the step input of your driver

#define dirPin 8

// instantiate a new object in our stepMotor library named slider

// we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin

stepMotor slider(stepPin, dirPin);

// setup() loop, the Arduino only runs through this once

void setup() {

}

// loop() loop, the Arduino continuously cycles through this as fast as it can

void loop() {

slider.step(50); // step our motor at a given frequency (Hz)

}

#include “stepLib.h”

// define our step pins

# define sliderStep 9

# define panStep 11

# define tiltStep 7

// define our direction pins

# define sliderDir 8

# define panDir 10

# define tiltDir 6

// instantiate a new object in our stepMotor library named slider

// we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin

stepMotor slider(sliderStep, sliderDir);

stepMotor pan(panStep, panDir);

stepMotor tilt(tiltStep, tiltDir);

// setup() loop, the Arduino only runs through this once

void setup() {

}

// loop() loop, the Arduino continuously cycles through this as fast as it can

void loop() {

slider.step(50); // step our motor at a given frequency (Hz)

pan.step(10); // step our motor at a given frequency (Hz)

tilt.step(100); // step our motor at a given frequency (Hz)

}

#ifndef _stepLib_h_

#define _stepLib_h_

#include “Arduino.h”

// define our stepper class

class stepMotor {

public:

stepMotor(byte stepPin, byte dirPin); // our stepper object with variables stepPin and dirPin

void step(unsigned int stepFreq); // our stepping function which takes as an input our stepping frequency

void setDir(boolean dir); // function that allows us to set our direction of rotation

private:

unsigned long _time; // current time

unsigned long _lastStepTime; // time at which we last stepped

unsigned long _stepPeriod; // time between a half period - this is the same as our delay(X) of part 1

byte _stepPin;

byte _dirPin;

boolean _stepCycle; // defines if we are on the HIGH or LOW side of our step cycle

};

#endif

#include “Arduino.h”

#include “stepLib.h”

// used for declaring our motor and initializing it

stepMotor::stepMotor(byte stepPin, byte dirPin) {

_stepPin = stepPin;

_dirPin = dirPin;

// define our digital pins as output

pinMode(_stepPin, OUTPUT);

pinMode(_dirPin, OUTPUT);

// initialize our digital pins to LOW

digitalWrite(_stepPin, LOW);

digitalWrite(_dirPin, LOW);

_stepCycle = false; // this keeps track of which end of the step cycle we are on: high or low

}

// function responsible for driving our digital pins high/low at the proper frequency

// input is the stepping frequency

void stepMotor::step(unsigned int stepFreq) {

_time = micros(); // get the current time

_stepPeriod = 1000000 / stepFreq; // get our step period (in micro-seconds) from the user given step frequency; we lose a bit of accuracy here since we’ve defined _stepPeriod as an unsigned long instead of a float, but that‘s ok.。.

// if the proper amount of time has passed, let’s go ahead and proceed to the next half of our step cycle

if (_time 》= _lastStepTime + _stepPeriod) {

digitalWrite(_stepPin, _stepCycle == true); // a compact way of writing either HIGH/LOW to our step pin based on where we are on our step cycle

_stepCycle = !_stepCycle; // this simply flips our Boolean

_lastStepTime = _time; // update the time we last stepped

}

}

// given a boolean user input, set our direction of travel to that input

void stepMotor::setDir(boolean dir) {

digitalWrite(_dirPin, dir);

}

#include “stepLib.h”

// define our step pins

# define sliderStep 9

# define panStep 11

# define tiltStep 7

// define our direction pins

# define sliderDir 8

# define panDir 10

# define tiltDir 6

// define the pins on which we‘ve put our N.O. buttons

#define button1 2

#define button2 3

// our motor step frequencies

int sliderFreq = 300;

int panFreq = 10;

int tiltFreq = 100;

// instantiate a new object in our stepMotor library named slider

// we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin

stepMotor slider(sliderStep, sliderDir);

stepMotor pan(panStep, panDir);

stepMotor tilt(tiltStep, tiltDir);

// setup() loop, the Arduino only runs through this once

void setup() {

// define our button pins as input pullup type - see http://arduino.cc/en/Tutorial/DigitalPins#.Uyphr4WN7q4

pinMode(button1, INPUT_PULLUP);

pinMode(button2, INPUT_PULLUP);

}

// loop() loop, the Arduino continuously cycles through this as fast as it can

void loop() {

if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // if button1 is pressed and button2 is not pressed

slider.setDir(true);

pan.setDir(true);

tilt.setDir(true);

} else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // if btton1 is not pressed and button2 is pressed

slider.setDir(false);

pan.setDir(false);

tilt.setDir(false);

}

if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // if either button is pressed

slider.step(sliderFreq); // step our motor at a given frequency (Hz)

pan.step(panFreq); // step our motor at a given frequency (Hz)

tilt.step(tiltFreq); // step our motor at a given frequency (Hz)

}

if (digitalRead(button1) == LOW && digitalRead(button2) == LOW) { // if both buttons are pressed together

sliderFreq += 10;

panFreq += 10;

tiltFreq += 10;

delay(10); // delay just a short while otherwise the double button presses causes our frequency to increase too quickly (we need to allow for the user to release the buttons)

}

}

#include “stepLib.h”

// define our step pins

# define sliderStep 9

# define panStep 11

# define tiltStep 7

// define our direction pins

# define sliderDir 8

# define panDir 10

# define tiltDir 6

// define the pins on which we’ve put our N.O. buttons

#define button1 2

#define button2 3

// define our joystick pins; NOTE we are using analog pins, not digital

#define LRjoystickPin 27 // left-right joystick

#define UDjoystickPin 28 // up-down joystick

// our motor step frequencies

int sliderFreq = 50;

int panFreq = 300;

int tiltFreq = 100;

// other variables

byte deadband = 50; // size of deadband, from joystick neutral position, in which we assume we are reading 0

unsigned int LRjoyValue = 0;

unsigned int UDjoyValue = 0;

// instantiate a new object in our stepMotor library named slider

// we are essentially declaring that we want to add a stepper motor named slider that has our defined stepPin and dirPin

stepMotor slider(sliderStep, sliderDir);

stepMotor pan(panStep, panDir);

stepMotor tilt(tiltStep, tiltDir);

// setup() loop, the Arduino only runs through this once

void setup() {

// define our button pins as input pullup type - see http://arduino.cc/en/Tutorial/DigitalPins#.Uyphr4WN7q4

pinMode(button1, INPUT_PULLUP);

pinMode(button2, INPUT_PULLUP);

pinMode(LRjoystickPin, INPUT);

pinMode(UDjoystickPin, INPUT);

}

// loop() loop, the Arduino continuously cycles through this as fast as it can

void loop() {

// read our joystick values and store them

LRjoyValue = analogRead(LRjoystickPin); // acts just like digitalRead, but for analog pins

UDjoyValue = analogRead(UDjoystickPin); // acts just like digitalRead, but for analog pins

// control our pan with the LR joystick

if (LRjoyValue 》 512+ deadband) { // joystick is outside of deadband, move right

pan.setDir(true);

pan.step(panFreq);

} else if (LRjoyValue 《 512- deadband) { // joystick is outside of deadband, move left

pan.setDir(false);

pan.step(panFreq);

}

// control our tilt with the UD joystick

if (UDjoyValue 》 512 + deadband) { // joystick is outside of deadband, move up

tilt.setDir(true);

tilt.step(panFreq);

} else if (UDjoyValue 《 512 - deadband) { // joystick is outside of deadband, move down

tilt.setDir(false);

tilt.step(panFreq);

}

// control our slider stepper with the two buttons, just like we did previously

if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // if button1 is pressed and button2 is not pressed

slider.setDir(true);

} else if (digitalRead(button1) == HIGH && digitalRead(button2) == LOW) { // if btton1 is not pressed and button2 is pressed

slider.setDir(false);

}

if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // if either button is pressed

slider.step(sliderFreq); // step our motor at a given frequency (Hz)

}

}

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

    关注

    142

    文章

    9031

    浏览量

    145699
  • 机械臂
    +关注

    关注

    12

    文章

    515

    浏览量

    24620
收藏 人收藏

    评论

    相关推荐

    机械的高效运作,连接器起关键作用

    了众多危险、重复的工作。 机械的工作原理      机械的运动控制是通过控制电机和传动装置来实现的。控制
    的头像 发表于 11-11 18:07 245次阅读

    在单个C2000™MCU上使用FCL和SFRA进行电机控制

    电子发烧友网站提供《在单个C2000™MCU上使用FCL和SFRA进行电机控制.pdf》资料免费下载
    发表于 09-14 09:40 0次下载
    在单个C2000™MCU上使用FCL和SFRA进行<b class='flag-5'>双</b><b class='flag-5'>轴</b><b class='flag-5'>电机</b>控制

    带你了解中空步进电机作用

    ‌中空步进电机的主要作用包括优化机械设计、方便布线及节约设计空间和生产成本,同时满足特定的精度要求。 中空步进电机,也称为空心轴步进
    的头像 发表于 09-05 14:44 480次阅读
    带你了解中空<b class='flag-5'>轴</b>步进<b class='flag-5'>电机</b>作用

    【原创】 drawbot 平面机械scara写字画画机器人DIY教程贴

    /1CdGoDr8WFIMfic-iPf5Znw 提取码:m1ov 项目简介:桌面级scara机械,运动机构为两个42步进电机和一个9g舵机,控制板为mega 2560 和ramps 1.4,其他部件主要为
    发表于 08-30 11:54

    OrangePi AIpro应用:机械应用开发指南

    2024世界人工智能大会上,香橙派携OrangePiAIpro20T在世博展览馆H1-A301展区亮相,给大家带来AI+互动的沉浸式体验。其中,搭载OrangePiAIpro开发板的智能机械吸引了
    的头像 发表于 08-19 16:42 597次阅读
    OrangePi AIpro应用:<b class='flag-5'>机械</b><b class='flag-5'>臂</b>应用开发指南

    工业机器人和机械的设计、功能和应用有哪些区别?

    机械是一种由多个关节连接而成的机械结构,类似于人的胳膊。它通常具有可旋转或可伸缩的关节,使其能够在空间中执行精确的定位和操作。机械通常由
    的头像 发表于 08-16 09:43 508次阅读

    大象机器人开源协作机械机械接入GPT4o大模型!

    本文已经或者同济子豪兄作者授权对文章进行编辑和转载 引言 随着人工智能和机器人技术的快速发展,机械在工业、医疗和服务业等领域的应用越来越广泛。通过结合大模型和多模态AI,机械能够实
    的头像 发表于 07-03 14:09 952次阅读
    大象机器人开源协作<b class='flag-5'>机械</b><b class='flag-5'>臂</b><b class='flag-5'>机械</b><b class='flag-5'>臂</b>接入GPT4o大模型!

    国产Cortex-A55人工智能教学实验箱_基于Python机械跳舞实验案例分享

    又不必要。 从力学的角度分析,物件在空间只有6个自由度。因此为抓取和传送在空间不同位置和方位物件,传送机构也应具有6个自由度。 实验程序流程 1、创建机械对象 2、机械
    发表于 06-28 14:37

    步进电机的结构和特点

    步进电机(也称为两相步进电机)是一种特殊的电机类型,它能够将电脉冲信号转换为精确的角位移或线位移。这种
    的头像 发表于 06-20 16:30 664次阅读
    <b class='flag-5'>双</b><b class='flag-5'>极</b>步进<b class='flag-5'>电机</b>的结构和特点

    基于六维力传感器的机械自动装配应用

    六维力传感器是一种特殊的力觉传感器,可以测量物体在笛卡尔坐标系下三个轴向的力和力矩,其内部采用高度敏感的材料和精密机械构造,可以为机械提供更高的测量精度,满足不同场景下的测量需求。作为机械
    的头像 发表于 06-06 13:49 796次阅读
    基于六维力传感器的<b class='flag-5'>机械</b><b class='flag-5'>臂</b>自动装配应用

    机械技术的前沿探索:年度案例回顾!

    在过去的几年里,机械技术经历了前所未有的发展,其应用领域从传统的制造业扩展到了医疗、服务、物流等多个新兴行业。这种跨界扩展得益于科技的飞速进步,尤其是在传感器、控制系统和人工智能领域的突破。特别是
    的头像 发表于 03-12 15:14 1156次阅读
    <b class='flag-5'>机械</b><b class='flag-5'>臂</b>技术的前沿探索:年度案例回顾!

    如何去提升机械的位置控制性能?

    控制性能。   精度衡量:直接测量机械末端的位置比较困难,这里采用一种近似的方式,比较机械指令角度与实际编码器反馈角度间的偏差值。
    的头像 发表于 03-05 08:43 1013次阅读
    如何去提升<b class='flag-5'>机械</b><b class='flag-5'>臂</b>的位置控制性能?

    步进电机单极性和的优缺点

    步进电机连接和单极连接是指其电气接线方式,这两种方式影响电机的驱动方法、控制电路设计以及性能。了解这些接线方式对于正确选择和使用步进电机
    的头像 发表于 02-06 10:42 2537次阅读
    步进<b class='flag-5'>电机</b>单极性和<b class='flag-5'>双</b><b class='flag-5'>极</b>的优缺点

    【国产FPGA+OMAPL138开发板体验】(原创)2.手把手玩转游戏机械

    。这可能涉及到设置通信协议、数据打包/解包、错误处理等。 3.2 机械驱动 根据机械的规格和通信协议,编写驱动以控制其运动。这可能包括控制电机
    发表于 02-01 20:18

    使用ChatGPT学习大象机器人六协作机械mechArm!

    调试的过程中,出现了一些问题,在识别收拾的时候,它是一直识别,这就意味着如果在1s中内识别了10次的话,会给机械发送10个命令,这样肯定不是我一开始所设想的。我一开始的想法是,当相机识别到手势的时候就会给机械
    的头像 发表于 01-31 14:39 684次阅读
    使用ChatGPT学习大象机器人六<b class='flag-5'>轴</b>协作<b class='flag-5'>机械</b><b class='flag-5'>臂</b>mechArm!