csit.selu.educsit.selu.edu/.../report_documents/zachary_guy_final_report_fall… · web viewthis...

42
2 DOF Robotic Arm Zachary Guy

Upload: others

Post on 31-Aug-2019

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

2 DOF Robotic Arm

Zachary Guy11/28/18

Fall 2018 – ET 493

Advisor: Dr. Mohammad SaadehInstructor: Dr. Cris Koutsougeras

Page 2: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Abstract

This project builds upon a past project completed by Dr. Saadeh and a former student. The former project dealt with controlling the position, speed, and acceleration of a single phase 110V AC servo motor. This project will be an extension of that as a 2 DOF Robotic Arm is attached to the end of the motor, and with the use of an additional motor, the two links of the robotic arm will be able to rotate independently. These arms will be connected and maneuvered via pulleys and belts that are connected to the shafts of the AC motors. A certain profile will seek to be obtained and controlled with the use of a teaching pendant. The project will cover such areas as: mechanisms, motion, dynamics, motor control, programming, and electronics.

Page 3: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Introduction

In a recent Senior Design project, Dr. Saadeh and a former Engineering Technology (ET) student worked on controlling the position, speed, and acceleration of a single-phase 110V AC servo motor. This control was obtainable with the programming and use of a teach pendant. The previous design didn’t transmit the motion to an arm. Rather, only a 3D printed shaft sleeve with an arrow was attached to the shaft of the motor to show the direction of rotation and positioning accuracy of the system. This project continues the previous efforts through the addition of a second motor and two independently moving arms to achieve a 2 DOF (Two Degrees of Freedom) Robotic Arm. Each motor will be responsible for moving one of the two arms and controlling its position, speed, and acceleration. The system uses pulleys and belts that are either fixed to each arm (thus the arm rotates with the pulley) or allowed to freely revolve around a shaft (to transmit motion to another arm). An additional AC servo motor will be acquired for this purpose, then the system will be controllable through the use of a teach pendant.

Background

The term “robotics” as it is presently used, was not introduced until 1941 by Science Fiction writer Isaac Asimov. The use of the word is to describe the technology, study, and use of robots. The first industrial robot was designed by George Devol. It was called the Unimate, and helped to revolutionize the manufacturing world. It was conceived from a design for a mechanical arm patented in 1954 (granted in 1961) by Devol, and was developed as a result of the foresight and business acumen of Joseph Engelberger - the Father of Robotics.“The number of industrial robots deployed worldwide will increase to around 2.6 million units by 2019. That’s about one million units more than in the record-breaking year of 2015. Broken down according to sectors, around 70 percent of industrial robots are currently at work in the automotive, electrical/electronic and metal and machinery industry segments. In 2015, the strongest growth in the number of operational units recorded here was registered in the electronics industry, which boasted a rise of 18 percent. The metal industry posted an increase of 16 percent, with the automotive sector growing by 10 percent.”“The USA is currently the fourth largest single market for industrial robots in the world. Within the NAFTA area (USA, Canada and Mexico), the total number of newly installed industrial robots rose by 17 percent to a new record of some 36,000 units (2015). The leader of the pack was the USA, accounting for three-quarters of all units sold. 5 percent growth was recorded. With a comparatively much smaller amount of units, the demand in Canada increased by 49 percent (5,466 units), while that in Mexico grew by 119 percent (3,474 units). With a stable economic situation, it may be expected that North America will see average annual growth of 5 to 10 percent in sales of robots from 2016 to 2019.The USA plays a leading role when it comes to automation in the automotive industry. US car makers are ranked third in robot density, behind Japan and the Republic of Korea. The US automotive industry has performed well over the last six years. 2015 proved to be the most successful year since 2005. Major manufacturers from the US, Europe and Asia embarked on restructuring programmes resulting in the installation of some 80,000 industrial robots between 2010 and 2015. This is the largest investment worldwide, second only to China at around 90,000 units.”

Page 4: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Project Goals

The deliverables discussed previously in the project proposal are as follows:

1. Mechanical Design

a. Motion Transmission

b. Linkage

c. Selection of Belts/Pulleys

2. Order Motor and Controller

3. Build Prototype

Progress Report for First Semester

Mechanical Design

My original design plans changed as the project progressed (See Fig. 1). I began with a design made in Autodesk Inventor that had the two motors placed side-by-side, with Link 1 being attached to the Motor 2. With the use of a dual-ball bearing I intended Link 1 to be able to rotate with the use of pulleys and a belt attached to Motor 1, without rotating when Motor 2 would be in operation. A pulley attached to Motor 2 would allow a belt to run up Arm 1 and be attached to a pulley connected to Link 2 to allow that arm to rotate.

Upon further review, this design would not be able to meet the objective of the project as it was proving to be difficult to figure out how to attach everything together without arms rotating with the wrong motor. Perhaps this design can be reviewed in the future, with the use of a dual-ball bearing and different servo motors.

Fig. 1: Initial Design – Autodesk Drawing

Page 5: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 1: Initial Design – Side View

Fig. 1: Initial Design – Isometric View

After meeting with Dr. Saadeh, a new design plan was reached, and this was the design that we followed for this semester (See Fig. 2).

With this design, Motors 1 and 2 will be facing towards each other and Link 1 will be fixed to the shaft of Motor 1. A D-shaft that will be going through Link 1, will support a 15T Pinion pulley, and be connected to the shaft of Motor 2 to allow for the rotation of the shaft and pulley, without rotating Link 1. A timing belt that has a 48” (240T) circumference is placed around Pulley 1 (15T Pinion Pulley) and run up the inside of the C-channel of Link 1. At the end of Arm 1 is Pulley 2 (15T Pinion Pulley). Pulley 2 is on another D-shaft that will run through Link 1 and into Link 2. With the use of clamps and bearings, when Pulley 2 rotates with the help of the belt and Pulley 1, Link 2 will rotate.

Page 6: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 2: Revised Design – Autodesk Drawing

Fig. 2: Revised Design – Side View

Fig. 2: Revised Design – Back View

Page 7: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 2: Revised Design – Top View

Fig. 2: Revised Design – Isometric View

Page 8: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 2: Revised Design – Motor used in Autodesk

Fig. 2: Revised Design – 3-D Printed Shaft Adapter Concept

After ordering some parts, it was determined that not all would be necessary, and that a few changes needed to be made. The changes including ordering the D-shafts mentioned and obtaining clamps that would be compatible with these shafts. The 48” belt was selected by using a belt length calculator from online (See References).

Page 9: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

As of right now, both links have been connected to each other and the second link rotates with the usage of the belt and pulleys. After further research and design, it was determined how to attach Link 1 to the shaft of Motor 1, as the shaft was keyed and not compatible with the C-channel of Link 1. A shaft adapter would be the solution to the linkage problem. An adapter for the shaft was not able to found on the market, and therefore a unique part was designed in Autodesk Inventor that would serve as the shaft adapter (See Fig. 2-2a and Fig. 2-2b). The initial design of the adapter would have worked if able to be made out of metal and the holes could be threaded. However, since the material that the 3-D printers are capable of using are only plastics, adjustments had to be made and the final design of the adapter was obtained. This design included using an off-set to allow for a M6-1.00 x 12 bolt to fasten the adapter to the motor shaft. For the side that would connect to the D-Shaft, the off-set was removed, as it could be accomplished using a D-Clamp Hub and Block Spacer from in house. After the printing of the adapters, we are able to attach Link 1 to the shaft of Motor 1, and able to attach the D-shaft protruding from Link 1 to the shaft of Motor 2.

Fig. 2-2a: Initial Shaft Adapter Design

Fig. 2-2b: Final Design, Adapter w/ off-set

Page 10: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 2-2b: Final Design, Adapter w/ off-set

Fig. 2-2b: Final Design, Adapter w/o off-set

Fig. 2-2b: Final Design, Adapter w/o off-set

Page 11: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

The first motor and controller from the original project have been fixed to a wooden base that was constructed by the former student. The base for the second motor and controller was constructed from ½” plywood and followed the design of the original base (See Fig. 3).

Fig. 3: Autodesk Rendering of Motor Base

Fig. 3: Existing Project – Teach Pendant

Page 12: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 3: Existing Project – Motor with Pointer

Fig. 3: Existing Project – Wiring of Servo Drive

Page 13: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Order Motor and Controller

The motor that has been ordered is: 11A-DST-A6HK1 from Dynamic Motor Motion (DMM).The data sheet for this motor is included in this report (See Table 1). This motor was selected because it matches the motor used in the previous project.

The Servo Drive that has been ordered is: DYN4-H01A2-00 from DMM.

Both the motor and drive have arrived, and have been secured to base.

Table 1: AC Servo Motor Specifications

Rated Voltage 200 VRated Output 1.0 kWRated Torque 4.77 N-mInst. Max. Torque 14.3 N-mRated Current 8.2 AMax. Current 24.6 ARated Speed 1500 rpmMax. Speed 3000 rpmRotor Inertia 8.5 kg-cm^2Torque Coefficient 0.774 N-m/AMass 8.95 kgRatings Time Rating: Continuous

Thermal Class: FExcitation Method: Permanent MagnetInsulation Resistance: DC500V, >20MΩNoise: ≤60dB; No Special Noise

Environment Ambient Temperature: 0-40 °CStorage: -20-50°CAmbient Humidity: 20-80%No Condensation

Enclosure IP65Shock 98m/s^2 Max. (10G)Applicable Servo Drive DYN4

Page 14: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Build Prototype

The assembly phase of the project is complete. The pictures included show the current state of the project and the sub-assemblies (See Fig. 4).

Fig. 4: View of Motor attached to new base

Page 15: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 4: Top View of Project (w/o shaft adapters)

Page 16: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 4: View of Link 1 w/ D-Shaft attached to hub and spacer

Page 17: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 4: Connection of Link 1 to Link 2

Page 18: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 4: Current Project Status – Wiring of Servo Drive

Page 19: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 4: View of 2 DOF Robotic Arm Prototype

Page 20: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Fig. 4: Shaft Adapters attached to Link 1 (left) and D Shaft (right)

CodingAt this stage in the project, extensive coding has not been accomplished. The Arduino codes from DMM have been obtained (See Coding Fig. 2), and several videos and code samples have been researched in order to learn how to control the motor with the servo drive. The Arduino board itself does not control the motor, the Arduino sends code to the servo drive, which then sends a signal to the motor to execute. The current aim of the code is to develop a program that will allow the user to press a push button to increase speed in one direction, and then to press another push button to decrease speed and eventually change the direction of rotation of the motor. I currently have a code that will reposition a small servo motor with the use of two push buttons, but I have yet to develop code to accomplish previously stated goal (See Coding Fig. 1)

Page 21: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Challenges

The main challenge faced during the project was determining how to connect Link 1 to the Motor. This was an obstacle due to the dimensions of the motor shaft not being equal to the dimensions of the C-Channel link. The solution to this challenge was presented earlier under “Mechanical Design”.

Another challenge faced included the apporiate determination of the belt and pulley to use. After researching which belt to use (see Fig. 5), it was determined that a timing belt would provide the most control in a low speed application like this project. With ServoCity (see References) we were able to obtain small pinion pulleys and a timing belt of pre-determined length as discussed in “Mechanical Design”.

Learning to generate code and modify the existing code will take extensive study and practice as this is a field that I am not confident in yet. More research and study still needs to be completed at this point in the project.

Fig. 5: Timing Belt Research – From Robotpark.com

Page 22: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

Next Semester Plans

For next semester there is plenty of work that will need to be done in order to finish this project.

Control of 2 – DOF Robotic Arm:

- Integrating developed code for small servo motor control with the existing code from DMM to control our AC Servo Motors

- Coding that allows control of both servo motors independent of one another (perhaps with the use of four push buttons)

Trajectory Planning:

- Research on trajectory planning and learn how to manipulate Link 1 and Link 2 to reach desired location

Teach Pendant Update:

- Redesign Teach Pendant to have more options for user to choose from to obtain desired position, velocity, and acceleration of robotic arm.

Part Number Part Description Quantity Needed11A-DST-A6HK1 AC Servo Motor 2DYN4-H01A2-00 Servo Drive 2

585462 18” C-Channel 1585466 24” C-Channel 1615434 15T Pinion Pulley 2

B375-480XL 48” Circumference Timing Belt 1545619 Clamping D-Hub 4634080 4” D-Shaft 1634082 5” D-Shaft 1535198 Flanged Ball Bearings 4

CAEN-HH3-TSP Encoder Cable 1CAMP-HH3-TSP Motor Power Cable 1

Table 2: Parts Needed

Page 23: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

// Sketch

#include <Servo.h> // add servo library#define sw1_pin 5#define sw2_pin 6Servo myservo; // create servo object to control a servo

volatile boolean sw1 = false;volatile boolean sw2 = false;

uint8_t sw1ButtonState = 0;uint8_t sw2ButtonState = 0;

uint8_t lastsw1ButtonState = 0;uint8_t lastsw2ButtonState = 0;

void setup() { Serial.begin(9600); pinMode(sw1_pin, INPUT_PULLUP); pinMode(sw2_pin, INPUT_PULLUP); myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo.write(90); // sets starting point}

void loop() { checkIfSw1ButtonIsPressed(); checkIfSw2ButtonIsPressed();

if( sw1){ Serial.println("sw1"); sw1 = false; myservo.write(0); delay(15); } else if( sw2){ Serial.println("sw2"); sw2 = false; myservo.write(180); delay(15); } // waits for the servo to get there}void checkIfSw1ButtonIsPressed()

Coding Fig. 1-1{

Page 24: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

sw1ButtonState = digitalRead(sw1_pin); if (sw1ButtonState != lastsw1ButtonState) { if ( sw1ButtonState == 0) { sw1=true; } delay(50); } lastsw1ButtonState = sw1ButtonState; }

void checkIfSw2ButtonIsPressed(){ sw2ButtonState = digitalRead(sw2_pin); if (sw2ButtonState != lastsw2ButtonState) { if ( sw2ButtonState == 0) { sw2=true; } delay(50); } lastsw2ButtonState = sw2ButtonState;}

Coding Fig. 1-2

/*

Page 25: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

DYN232M_Arduino_SourceCode.ino - DMM Technology Corp. DYN2 and DYN4 AC Servo drive Arduino UART RS232 communication code. Version 1.0 - Release May 2018 Distributed By: DMM Technology Corp. www.dmm-tech.com*//**/#define Go_Absolute_Pos 0x01#define Go_Relative_Pos 0x03#define Is_AbsPos32 0x1b#define General_Read 0x0e #define Is_TrqCurrent 0x1E#define Read_MainGain 0x18#define Set_MainGain 0x10#define Set_SpeedGain 0x11#define Set_IntGain 0x12#define Set_HighSpeed 0x14#define Set_HighAccel 0x15#define Set_Pos_OnRange 0x16#define Is_MainGain 0x10#define Is_SpeedGain 0x11#define Is_IntGain 0x12#define Is_TrqCons 0x13#define Is_HighSpeed 0x14#define Is_HighAccel 0x15#define Is_Driver_ID 0x16#define Is_Pos_OnRange 0x17#define Is_Status 0x19#define Is_Config 0x1a// Add additional function code according to user requirement/*Variables*/char InputBuffer[256]; //Input buffer from RS232,char OutputBuffer[256]; //Output buffer to RS232,unsigned char InBfTopPointer, InBfBtmPointer; //input buffer pointersunsigned char OutBfTopPointer, OutBfBtmPointer; //output buffer pointersunsigned char Read_Package_Buffer[8], Read_Num, Read_Package_Length, Global_Func;unsigned char MotorPosition32Ready_Flag, MotorTorqueCurrentReady_Flag, MainGainRead_Flag;unsigned char Driver_MainGain, Driver_SpeedGain, Driver_IntGain, Driver_TrqCons, Driver_HighSpeed, Driver_HighAccel,Driver_ReadID,Driver_Status,Driver_Config,Driver_OnRange;long Motor_Pos32, MotorTorqueCurrent;/*Prototypes*/void move_rel32(char ID, long pos);

Coding Fig. 2-1void ReadMotorTorqueCurrent(char ID);

Page 26: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

void ReadMotorPosition32(char ID);void move_abs32(char MotorID, long Pos32);void Turn_const_speed(char ID, long spd);void ReadPackage(void);void Get_Function(void);long Cal_SignValue(unsigned char One_Package[8]);long Cal_Value(unsigned char One_Package[8]);void Send_Package(char ID , long Displacement);void Make_CRC_Send(unsigned char Plength, unsigned char B[8]);/**/

void setup(){ Serial.begin(38400); // Serial0 used to write to Serial Monitor Serial3.begin(38400); // Servo drive connected to Serial3 pinMode(LED_BUILTIN, OUTPUT); Serial.println("PROGRAM STARTING");}

void loop(){ Serial.println("STARTING LOOP"); digitalWrite(LED_BUILTIN, HIGH); move_rel32(1, 65536); delay(250); digitalWrite(LED_BUILTIN, LOW); move_rel32(2, 16384); delay(250); digitalWrite(LED_BUILTIN, HIGH); move_rel32(3, -65536); delay(1000);

ReadMotorPosition32(1); Serial.print("Axis 1 Encoder Position: "); Serial.println(Motor_Pos32); ReadMotorPosition32(2); Serial.print("Axis 2 Encoder Position: "); Serial.println(Motor_Pos32); ReadMotorPosition32(3); Serial.print("Axis 3 Encoder Position: "); Serial.println(Motor_Pos32); digitalWrite(LED_BUILTIN, LOW); move_abs32(1, 0); move_abs32(2, 0); move_abs32(3, 0); delay(1000); Coding Fig. 2-2 Serial.println("END LOOP"); Serial.println("");}

Page 27: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

/////////////////////////// SAMPLE COMMAND FUNCTIONS ////////////////////////////////////

void move_rel32(char ID, long pos){ char Axis_Num = ID; Global_Func = (char)Go_Relative_Pos; Send_Package(Axis_Num, pos);}void ReadMotorTorqueCurrent(char ID) { Global_Func = General_Read; Send_Package(ID , Is_TrqCurrent); MotorTorqueCurrentReady_Flag = 0xff; while(MotorTorqueCurrentReady_Flag != 0x00) { ReadPackage(); }}void ReadMotorPosition32(char ID) { Global_Func = (char)General_Read; Send_Package(ID , Is_AbsPos32); MotorPosition32Ready_Flag = 0xff; while(MotorPosition32Ready_Flag != 0x00) { ReadPackage(); }}void move_abs32(char MotorID, long Pos32) { char Axis_Num = MotorID; Global_Func = (char)Go_Absolute_Pos; Send_Package(Axis_Num, Pos32);}

void Turn_const_speed(char ID, long spd){ char Axis_Num = ID; Global_Func = 0x0a; Send_Package(Axis_Num, spd);}

Coding Fig. 2-3

Page 28: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

////////////////////// DYN232M SERIAL PROTOCOL PACKAGE FUNCTIONS ///////////////////////////////

void ReadPackage(void) { unsigned char c, cif; while (Serial3.available() > 0) { InputBuffer[InBfTopPointer] = Serial3.read(); //Load InputBuffer with received packets InBfTopPointer++; } while (InBfBtmPointer != InBfTopPointer) { c = InputBuffer[InBfBtmPointer]; InBfBtmPointer++; cif = c & 0x80; if (cif == 0) { Read_Num = 0; Read_Package_Length = 0; } if (cif == 0 || Read_Num > 0) { Read_Package_Buffer[Read_Num] = c; Read_Num++; if (Read_Num == 2) { cif = c >> 5; cif = cif & 0x03; Read_Package_Length = 4 + cif; c = 0; } if (Read_Num == Read_Package_Length) { Get_Function(); Read_Num = 0; Read_Package_Length = 0; } } }}

void Get_Function(void) { char ID, ReceivedFunction_Code, CRC_Check; long Temp32; ID = Read_Package_Buffer[0] & 0x7f; ReceivedFunction_Code = Read_Package_Buffer[1] & 0x1f; Coding Fig. 2-4CRC_Check = 0; for (int i = 0; i < Read_Package_Length - 1; i++) {

Page 29: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

CRC_Check += Read_Package_Buffer[i]; } CRC_Check ^= Read_Package_Buffer[Read_Package_Length - 1]; CRC_Check &= 0x7f; if (CRC_Check != 0) { } else { switch (ReceivedFunction_Code) { case Is_AbsPos32: Motor_Pos32 = Cal_SignValue(Read_Package_Buffer); MotorPosition32Ready_Flag = 0x00; break; case Is_TrqCurrent:

MotorTorqueCurrent = Cal_SignValue(Read_Package_Buffer); break;

case Is_Status: Driver_Status = (char)Cal_SignValue(Read_Package_Buffer); // Driver_Status=drive status byte data break; case Is_Config: Temp32 = Cal_Value(Read_Package_Buffer); //Driver_Config = drive configuration setting break; case Is_MainGain: Driver_MainGain = (char)Cal_SignValue(Read_Package_Buffer); Driver_MainGain = Driver_MainGain & 0x7f; break; case Is_SpeedGain: Driver_SpeedGain = (char)Cal_SignValue(Read_Package_Buffer); Driver_SpeedGain = Driver_SpeedGain & 0x7f; break; case Is_IntGain: Driver_IntGain = (char)Cal_SignValue(Read_Package_Buffer); Driver_IntGain = Driver_IntGain & 0x7f; break; case Is_TrqCons: Driver_TrqCons = (char)Cal_SignValue(Read_Package_Buffer); Driver_TrqCons = Driver_TrqCons & 0x7f; break; case Is_HighSpeed: Coding Fig. 2-5 Driver_HighSpeed = (char)Cal_SignValue(Read_Package_Buffer); Driver_HighSpeed = Driver_HighSpeed & 0x7f; break;

Page 30: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

case Is_HighAccel: Driver_HighAccel = (char)Cal_SignValue(Read_Package_Buffer); Driver_HighAccel = Driver_HighAccel & 0x7f; break; case Is_Driver_ID: Driver_ReadID = ID; break; case Is_Pos_OnRange: Driver_OnRange = (char)Cal_SignValue(Read_Package_Buffer); Driver_OnRange = Driver_OnRange & 0x7f; break; } }}

long Cal_SignValue(unsigned char One_Package[8]) //Get data with sign - long{ char Package_Length,OneChar,i; long Lcmd; OneChar = One_Package[1]; OneChar = OneChar>>5; OneChar = OneChar&0x03; Package_Length = 4 + OneChar; OneChar = One_Package[2]; /*First byte 0x7f, bit 6 reprents sign */ OneChar = OneChar << 1; Lcmd = (long)OneChar; /* Sign extended to 32bits */ Lcmd = Lcmd >> 1; for(i=3;i<Package_Length-1;i++) { OneChar = One_Package[i]; OneChar &= 0x7f; Lcmd = Lcmd<<7; Lcmd += OneChar; } return(Lcmd); /* Lcmd : -2^27 ~ 2^27 - 1 */}long Cal_Value(unsigned char One_Package[8]){ char Package_Length,OneChar,i; long Lcmd; OneChar = One_Package[1]; OneChar = OneChar>>5; Coding Fig. 2-6OneChar = OneChar&0x03; Package_Length = 4 + OneChar;

Page 31: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

OneChar = One_Package[2]; /*First byte 0x7f, bit 6 reprents sign */ OneChar &= 0x7f; Lcmd = (long)OneChar; /*Sign extended to 32bits */ for(i=3;i<Package_Length-1;i++) { OneChar = One_Package[i]; OneChar &= 0x7f; Lcmd = Lcmd<<7; Lcmd += OneChar; } return(Lcmd); /*Lcmd : -2^27 ~ 2^27 - 1 */}void Send_Package(char ID , long Displacement) { unsigned char B[8], Package_Length, Function_Code; long TempLong; B[1] = B[2] = B[3] = B[4] = B[5] = (unsigned char)0x80; B[0] = ID & 0x7f; Function_Code = Global_Func & 0x1f; TempLong = Displacement & 0x0fffffff; //Max 28bits B[5] += (unsigned char)TempLong & 0x0000007f; TempLong = TempLong >> 7; B[4] += (unsigned char)TempLong & 0x0000007f; TempLong = TempLong >> 7; B[3] += (unsigned char)TempLong & 0x0000007f; TempLong = TempLong >> 7; B[2] += (unsigned char)TempLong & 0x0000007f; Package_Length = 7; TempLong = Displacement; TempLong = TempLong >> 20; if (( TempLong == 0x00000000) || ( TempLong == 0xffffffff)) { //Three byte data B[2] = B[3]; B[3] = B[4]; B[4] = B[5]; Package_Length = 6; } TempLong = Displacement; TempLong = TempLong >> 13; if (( TempLong == 0x00000000) || ( TempLong == 0xffffffff)) { //Two byte data B[2] = B[3]; B[3] = B[4]; Package_Length = 5; }

Coding Fig. 2-7TempLong = Displacement; TempLong = TempLong >> 6; if (( TempLong == 0x00000000) || ( TempLong == 0xffffffff)) { //One byte data

Page 32: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

B[2] = B[3]; Package_Length = 4; } B[1] += (Package_Length - 4) * 32 + Function_Code; Make_CRC_Send(Package_Length, B);}

void Make_CRC_Send(unsigned char Plength, unsigned char B[8]) { unsigned char Error_Check = 0; char RS232_HardwareShiftRegister; for (int i = 0; i < Plength - 1; i++) { OutputBuffer[OutBfTopPointer] = B[i]; OutBfTopPointer++; Error_Check += B[i]; } Error_Check = Error_Check | 0x80; OutputBuffer[OutBfTopPointer] = Error_Check; OutBfTopPointer++; while (OutBfBtmPointer != OutBfTopPointer) { RS232_HardwareShiftRegister = OutputBuffer[OutBfBtmPointer]; //Serial.print("RS232_HardwareShiftRegister: "); //Serial.println(RS232_HardwareShiftRegister, DEC); Serial3.write(RS232_HardwareShiftRegister); OutBfBtmPointer++; // Change to next byte in OutputBuffer to send }}

Coding Fig. 2-8

Referenceshttps://www.bbman.com/belt-length-calculator/

Page 33: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The

https://www.servocity.com/

http://www.dmm-tech.com/ac_servomotor_main_a1.html

https://www.orbiscnc.com/products/dmm-technology/dyn4-h01a2-00/

Page 34: csit.selu.educsit.selu.edu/.../Report_Documents/Zachary_Guy_Final_Report_Fall… · Web viewThis project builds upon a past project completed by Dr. Saadeh and a former student. The