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

步骤1:原理图和组件列表
这是我们在此项目中使用的完整原理图和可用组件的概述。
包含的组件如下:
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)
}
}

华为的激光雷达是虚晃一枪还是真功夫?
HTC成功出售手机业务给谷歌 HTC有望否极泰来股价大涨近6%
如何在RK3568开发板上实现USBNET模式?
如何推导电容式MEMS加速度计中使用的传递函数
解读MEMS智能传感器技术的新进展
如何使用双极电机创建3点轴机械臂
外媒:央行数字货币可以解决支付数据留在主要技术平台手中的隐私问题
晶体管的工作原理
工控主板启动时无法显示,原因有哪些
华为已经在威尔士进行了Open RAN技术测试?
余承东:华为mate9对标苹果 Mate9 Pro中国独享
智能手表PSRAM芯片存储方案的介绍
驾驶员监控系统提升安全性
从设计角度,以高压电缆为案例重点讨论高电压安全发展进步
小米手表Color评测 绝非盲目跟风
锂电池四大技术难题制约电动汽车的发展
浅谈5G通信系统中毫米波的天线设计
Cadence拓展与台积电和微软的合作,携手推进云端千兆级物理验证
以太坊的扩展性解决方案详细解读
一款开关降压型单节锰锂电池/磷酸铁锂电池充电管理芯片