当前位置:网站首页>Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
2022-06-25 06:28:00 【Xule and his friends】
What I have built is a three degree of freedom link manipulator , The reason for choosing to build this manipulator is that it is easy to operate , Easy to master , Easy to learn .
Here are some of the processes I'm learning to make this manipulator :
Main parts
Main control panel :arduino uno r3
Expansion board :cnc shield v3 Engraving machine expansion board
42 Stepper motor ,SG90 The motor ,PVC plate ,A4988 Driver module ,HC-06 modular
Because I like to list one thing , So I made a mind map :

And I also made a mathematical settlement on the coordinate self-determination :

Here's the code section :
In the code section , Due to my weak programming ability , Part of the code and programming thinking have learned from many B standing UP Lord , And this article is only to record my learning process of manipulator .
Phone mode and keyboard mode code :
/* The stepping mode of the motor must be in cnc Debugging on the extended version of the motor .
* Start the program , The program starts in keyboard control mode by default
* In keyboard mode ,'m' You can switch to the phone mode with one touch .
* Mobile phone mode
* In mobile mode ,'m' You can switch to keyboard mode with one key .
*/
#include <Servo.h>
#include <AccelStepper.h>
#include <SoftwareSerial.h>
SoftwareSerial BTserial(12, 13); // establish SoftwareSerial object ,RX Pin 12(SpnEn) Pick up SpnDir, TX Pin 13(SpnDir) Pick up SpnEn
// Define constants for motor control
const int enablePin = 8; // Enable the control pin
const int xdirPin = 5; // x Direction control pin
const int xstepPin = 2; // x Step control pin
const int ydirPin = 6; // y Direction control pin
const int ystepPin = 3; // y Step control pin
const int zdirPin = 7; // z Direction control pin
const int zstepPin = 4; // z Step control pin
const int clawMin = 144; // Store motor limits
const int clawMax = 180;
const int moveSteps = 5; // The number of operating steps used by the stepper motor for operation ( Only available in phone mode )
char cmd; // Motor command characters
int data; // Motor command parameters
char stepperName; // Control motor number
int stepNumber; // Running steps of stepping motor
int clawstep; // Target angle of gripper motor
bool mode = 1; //mode = 1: Keyboard mode , mode = 0: Mobile phone mode
int DSD = 15; //Default Servo Delay ( Default motor motion delay time )
// This variable is used to control the running speed of the motor . Increasing the value of this variable will
// Reduce the running speed of the motor to control the action speed of the manipulator .
int clawMoveStep = 2; // Every time you press the handle button , Steering gear movement ( Only available in phone mode )
Servo claw ; // Create servo motor object ——— Gripper motor
AccelStepper base_stepper(1,xstepPin,xdirPin); // Create stepper motor object ——— Base motor
AccelStepper forearm_stepper(1,ystepPin,ydirPin); // Create stepper motor object ——— Forearm motor
AccelStepper upperarm_stepper(1,zstepPin,zdirPin); // Create stepper motor object ——— Rear arm motor
void setup() {
pinMode(xstepPin,OUTPUT); // Arduino control A4988x The step pin is in output mode
pinMode(xdirPin,OUTPUT); // Arduino control A4988x The direction pin is in output mode
pinMode(ystepPin,OUTPUT); // Arduino control A4988y The step pin is in output mode
pinMode(ydirPin,OUTPUT); // Arduino control A4988y The direction pin is in output mode
pinMode(zstepPin,OUTPUT); // Arduino control A4988z The step pin is in output mode
pinMode(zdirPin,OUTPUT); // Arduino control A4988z The direction pin is in output mode
pinMode(enablePin,OUTPUT); // Arduino control A4988 The enable pin is in output mode
digitalWrite(enablePin,LOW); // Set the enable control pin to the low level so that
// The motor drive board enters the working state
claw.attach(11); // claw Servo actuator connection pin Z+ Steering gear code 'c'
delay(200); // Stability wait
claw.write(90);
delay(10);
Serial.begin(9600);
BTserial.begin(9600); // HC-06 Default baud rate 9600
Serial.println(F("/\\\\\\\\\\\\\\\\\\"));
Serial.println(F("****The robotic arm serves you*****"));
Serial.println(F("/\\\\\\\\\\\\\\\\\\"));
Serial.println(F(""));
Serial.println(F("Please input motor command:"));
Serial.print("HC-06 DEMO/TEST ");
BTserial.print("AT"); // Settings can be entered here HC-06 Bluetooth module AT Instructions .
// this AT Instructions must be HC-06 Bluetooth status input not connected .
base_stepper.setMaxSpeed(100); // Set the maximum motor speed to 500
base_stepper.setAcceleration(50.0); // Initialize the motor speed to 0 setSpeed(0);
forearm_stepper.setMaxSpeed(100);
forearm_stepper.setAcceleration(50.0);
upperarm_stepper.setMaxSpeed(100);
upperarm_stepper.setAcceleration(50.0);
claw.write(144);
base_stepper.setCurrentPosition(0);
forearm_stepper.setCurrentPosition(0);
upperarm_stepper.setCurrentPosition(0);
}
void loop() {
if (Serial.available()>0) { //Serial.available()>0 //BTserial.available()>0
cmd = Serial.read();
Serial.print(cmd);
if( mode == 1 ){
keyboard_input(cmd); // Keyboard control mode
} else {
cellphone_input(cmd); // Mobile control mode
}
}
base_stepper.run(); // The base motor runs
forearm_stepper.run(); // Forearm motor operation
upperarm_stepper.run(); // The rear arm motor operates
}
//Arduino Perform the corresponding operation according to the serial instruction
//
void keyboard_input(char cmd){
// Determine whether the wrong instruction information is input due to the wrong mode ( Enter the phone mode information in keyboard mode )
if ( cmd == 'w' || cmd == 's' || cmd == 'a' || cmd == 'd'
|| cmd == '5' || cmd == '4' || cmd == '6' || cmd == '8' ){
Serial.println("Warning!!! Warning!!! Warning!!! Currently in the keyboard_input");
delay(100);
while(Serial.available()>0) char wrongCommand = Serial.read(); // Clear the wrong instruction of serial port cache
return;
}
if( cmd == 'b' || cmd == 'f' || cmd == 'u'){
data = Serial.parseInt();
RunCommand(cmd,data);
}else{
switch (cmd){
case 'm' :// Switch to phone control mode
mode = 0;
Serial.println("Enter the cellphone control mode");
break;
case 'o' :// Reset the mechanical arm
reset_arm();
Serial.println("Receive command");
break;
case 'c' :// Gripper motor operates
int servoData = Serial.parseInt();
servoCmd(cmd, servoData, DSD); // Manipulator steering gear operation function ( Parameters : Steering gear name , Target angle , Delay / Speed )
Serial.println("Receive the claw operation command");
break;
default : // Unknown instruction feedback
Serial.println("Unknown Command.");
}
}
}
void cellphone_input (char cmd ){
// Determine whether humans enter the wrong command information due to the wrong mode ( Input keyboard mode information in mobile phone mode )
if (cmd == 'b' || cmd == 'f' || cmd == 'u' || cmd == 'v'){
Serial.println("Warning!!! Warning!!! Warning!!! Currently in the cellphone_input");
delay(100);
while(Serial.available()>0) char wrongCommand = Serial.read(); // Clear the wrong instruction of serial port cache
return;
}
int basestep;
int forearmstep;
int upperarmstep;
//int clawstep
switch(cmd){
case 'a' ://base_stepper towards the left
basestep = base_stepper.currentPosition() - moveSteps;
Serial.println("A run command was received");
delay(500);
base_stepper.moveTo(basestep);
//CellphoneRunCommand('a',basestep);
break;
case 'd' ://base_stepper towards the right
basestep = base_stepper.currentPosition() + moveSteps;
Serial.println("A run command was received");
delay(500);
base_stepper.moveTo(basestep);
//CellphoneRunCommand('d',basestep);
break;
case 'w' ://upperarm_stepper Down
upperarmstep = upperarm_stepper.currentPosition() - moveSteps;
Serial.println("A run command was received");
delay(500);
upperarm_stepper.moveTo(upperarmstep);
//CellphoneRunCommand('w',upperarmstep);
break;
case 's' ://upperarm_stepper Up
upperarmstep = upperarm_stepper.currentPosition() + moveSteps;
Serial.println("A run command was received");
delay(500);
upperarm_stepper.moveTo(upperarmstep);
//CellphoneRunCommand('s',upperarmstep);
break;
case '8' ://forearm_stepper Down
forearmstep = forearm_stepper.currentPosition() - moveSteps;
Serial.println("A run command was received");
delay(500);
forearm_stepper.moveTo(forearmstep);
//CellphoneRunCommand('8',forearmstep);
break;
case '5' ://forearm_stepper Up
forearmstep = forearm_stepper.currentPosition() + moveSteps;
Serial.println("A run command was received");
delay(500);
forearm_stepper.moveTo(forearmstep);
//CellphoneRunCommand('5',forearmstep);
break;
case '4' :// Clamping jaws open
Serial.println("Received Command: Claw Open Up");
clawstep = claw.read() - clawMoveStep;
servoCmd('c', clawstep, DSD);
break;
case '6' :// Gripper closed
Serial.println("Received Command: Claw Close Down");
clawstep = claw.read() + clawMoveStep;
servoCmd('c', clawstep, DSD);
break;
case 'm' : // Switch to keyboard control mode
mode = 1;
Serial.println("Enter the keyboard control mode");
break;
case 'o' :// Reset the mechanical arm
reset_arm();
Serial.println("Receive command");
break;
//default : // Unknown instruction feedback
//Serial.println("Unknown Command.");
}
}
void RunCommand(char stepperName,int stepNumber){
switch (stepperName){
case 'b' :// The base motor runs , utilize move Function to make the motor run in corresponding steps ( Example :b1024 - Run the motor 1024 Step )
Serial.println("A run command was received");
//delay(500);
base_stepper.move(stepNumber);
break;
case 'f' :
Serial.println("A run command was received");
//delay(500);
forearm_stepper.move(stepNumber);
break;
case 'u' :
Serial.println("A run command was received");
//delay(500);
upperarm_stepper.move(stepNumber);
break;
default: // Unknown instruction feedback
Serial.println("Unknown Command.");
}
}
void reset_arm(){// Manipulator reset function .
/*runToNewPosition And moveTo The functions are basically the same . The only difference is runToNewPosition Function will “block” The program runs .
* That is, before the motor reaches the target position ,Arduino The following program contents will not be executed .
*/
Serial.println("Receive command");
base_stepper.runToNewPosition(0);
forearm_stepper.runToNewPosition(0);
upperarm_stepper.runToNewPosition(0);
claw.write(145);
delay(500);
Serial.println("The reset command was completed");
}
void servoCmd(char servoName, int toPos, int servoDelay){
int fromPos; // Build variables , Store the initial movement angle value of the motor
if(toPos >= clawMin && toPos <= clawMax){
fromPos = claw.read(); // Gets the current motor angle value for “ Starting angle value of motor movement ”
} else {
Serial.println("+Warning: Claw Servo Value Out Of Limit!");
return;
}
// Command the gripper motor to run
if (fromPos <= toPos){ // If “ Starting angle value ” Less than “ Target angle value ”
for (int i=fromPos; i<=toPos; i++){
claw.write(i);
delay (15);
}
}else { // otherwise “ Starting angle value ” Greater than “ Target angle value ”
for (int i=fromPos; i>=toPos; i--){
claw.write(i);
delay (15);
Serial.println("Receive command");
}
}
}Coordinate self searching code :
float basepos;
float forearmpos;
float upperarmpos;
float upperarmpos1;
float upperarmpos2;
float pi=3.14;
float touying;
const int basehigh=13;
int duanbian;
int xiebian;
int x;
float y;
float z;
#include <AccelStepper.h>
// Define constants for motor control
const int enablePin = 8; // Enable the control pin
const int xdirPin = 5; // x Direction control pin
const int xstepPin = 2; // x Step control pin
const int ydirPin = 6; // y Direction control pin
const int ystepPin = 3; // y Step control pin
const int zdirPin = 7; // z Direction control pin
const int zstepPin = 4; // z Step control pin
const int Num=6;
const int upperarm=16;
const int forearm=14;
AccelStepper base_stepper(1,xstepPin,xdirPin); // Create stepper motor object ——— Base motor
AccelStepper forearm_stepper(1,ystepPin,ydirPin); // Create stepper motor object ——— Forearm motor
AccelStepper upperarm_stepper(1,zstepPin,zdirPin); // Create stepper motor object ——— Rear arm motor
void setup() {
pinMode(xstepPin,OUTPUT); // Arduino control A4988x The step pin is in output mode
pinMode(xdirPin,OUTPUT); // Arduino control A4988x The direction pin is in output mode
pinMode(ystepPin,OUTPUT); // Arduino control A4988y The step pin is in output mode
pinMode(ydirPin,OUTPUT); // Arduino control A4988y The direction pin is in output mode
pinMode(zstepPin,OUTPUT); // Arduino control A4988z The step pin is in output mode
pinMode(zdirPin,OUTPUT); // Arduino control A4988z The direction pin is in output mode
pinMode(enablePin,OUTPUT); // Arduino control A4988 The enable pin is in output mode
digitalWrite(enablePin,LOW); // Set the enable control pin to the low level so that
// The motor drive board enters the working state
Serial.begin(9600);
Serial.println(F("/\\\\\\\\\\\\\\\\\\"));
Serial.println(F("****The robotic arm serves you*****"));
Serial.println(F("/\\\\\\\\\\\\\\\\\\"));
Serial.println(F(""));
Serial.println(F("Please input motor command:"));
base_stepper.setMaxSpeed(100); // Set the maximum motor speed to 500
base_stepper.setAcceleration(50.0); // Initialize the motor speed to 0 setSpeed(0);
forearm_stepper.setMaxSpeed(100);
forearm_stepper.setAcceleration(50.0);
upperarm_stepper.setMaxSpeed(100);
upperarm_stepper.setAcceleration(50.0);
base_stepper.setCurrentPosition(0);
forearm_stepper.setCurrentPosition(0);
upperarm_stepper.setCurrentPosition(0);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>1){
int data = Serial.parseInt();
x=data/100;
y=abs((data-x*100)/10);
z=abs(data%10);
Serial.println(x);
Serial.println(y);
Serial.println(z);
calculate();
Serial.print("basepos= ");Serial.println(basepos);
Serial.print("upperarmpos= ");Serial.println(upperarmpos);
Serial.print("forearmpos= ");Serial.println(forearmpos);
RunCommand(basepos,upperarmpos,forearmpos);
base_stepper.run(); // The base motor runs
forearm_stepper.run(); // The rear arm motor operates
upperarm_stepper.run(); // Forearm motor operation
}
}
void calculate(){
basepos=atan(x/y)*(180/pi)/1.8;
// Bottom angle
delay(500);
touying=sqrt(pow(x,2)+pow(y,2))-Num;
delay(500);
duanbian=abs(basehigh-z);
xiebian=sqrt(pow(duanbian,2)+pow(touying,2));
upperarmpos1=(acos((pow(upperarm,2)+pow(xiebian,2)-pow(forearm,2))/(2*upperarm*xiebian)))*(180/pi);
if(basehigh==z){
upperarmpos2=0;
}else if(basehigh>z){
upperarmpos2=atan(touying/duanbian)* (180/pi)-90;
}
else if(basehigh<z){
upperarmpos2=atan(duanbian/touying)-90;
}
upperarmpos=(upperarmpos1+upperarmpos2-15)/1.8;
// Forearm angle
forearmpos=(acos((pow(upperarm,2)+pow(forearm,2)-pow(xiebian,2))/(2*upperarm*forearm))*(180/pi)+(upperarmpos-90))/1.8;
// Rear arm angle
}
void RunCommand(int b,int u,int f){
Serial.println("Receive command");
Serial.println(b);
Serial.println(u);
Serial.println(f);
upperarm_stepper.runToNewPosition(u);
delay(100);
forearm_stepper.runToNewPosition(f);
delay(500);
base_stepper.runToNewPosition(b);
delay(500);
}As a mechanical student , I really don't want to spend too much time on code ( Crying and laughing ), Not merging two codes , And my programming ability is very weak , There may be many errors in the code .
This article is for personal study only .
边栏推荐
- [short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]
- IQ debugging of Hisilicon platform ISP and image (1)
- Socket, network model notes
- JD 8 fleet stores search history, deletes history, clears history (not finished)
- Uni app wechat applet customer service chat function
- Analysis report on demand scale and Supply Prospect of global and Chinese thermal insulation materials market during the 14th Five Year Plan period 2022-2028
- How to open an account online? Is it safe to open an account online?
- Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
- China rehabilitation hospital industry operation benefit analysis and operation situation investigation report 2022
- Introduction to sap ui5 tools
猜你喜欢

Socket, network model notes

The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse

Exercise: completion
![[Suanli network] problems and challenges faced by the development of Suanli network](/img/90/1d537de057113e2b4754e76746f256.jpg)
[Suanli network] problems and challenges faced by the development of Suanli network

2022-02-19: fence installation. In a two-dimensional garden, there are some trees represented by (x, y) coordinates. As the installation cost is very expensive, your task is to enclose all the trees w

How to deploy locally developed SAP ui5 applications to ABAP servers

Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator

Microsoft issued a document to celebrate Net 20th anniversary!

Sleep quality today 67 points

Understand what ICMP Protocol is
随机推荐
Aviator an expression evaluation engine
[Suanli network] technological innovation of Suanli Network -- Key Technologies of green and security
How to use asemi FET 7n80 and how to use 7n80
What is the slice flag bit
Analysis report on investment and financing status and operation benefits of global and Chinese dental industry (2022 Edition)
An easy problem
JD 8 fleet stores search history, deletes history, clears history (not finished)
DataX tutorial (10) - hot plug principle of dataX plug-in
From file system to distributed file system
Analysis of common interview questions in redis
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
John
The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
Why study discrete mathematics
Observation configuring wmic
Go uses channel to control concurrency
ctfshow-misc
Fdisk command – disk partition
Methods for obtaining some information of equipment
Research Report on global and Chinese vaccine market profit forecast and the 14th five year plan development strategy 2022-2028