0% found this document useful (0 votes)
125 views

MATLAB GUI For The Robot Arm: Goal Your

This document provides instructions for creating a MATLAB GUI to control a robot arm. The GUI allows controlling 5 joint sliders, displaying joint angles, controlling a gripper slider, connecting to the robot arm serially, and displaying the arm position to match the real robot. The tasks involve opening a serial connection, sending gripper commands from the slider, and sending position commands from the joint sliders. An Arduino example is provided to control the arm without requiring additional Arduino code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

MATLAB GUI For The Robot Arm: Goal Your

This document provides instructions for creating a MATLAB GUI to control a robot arm. The GUI allows controlling 5 joint sliders, displaying joint angles, controlling a gripper slider, connecting to the robot arm serially, and displaying the arm position to match the real robot. The tasks involve opening a serial connection, sending gripper commands from the slider, and sending position commands from the joint sliders. An Arduino example is provided to control the arm without requiring additional Arduino code.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MATLABGUIfortherobotarm

Goal
Thegoalofthisexerciseistouse
your
MATLABGUIDEprogramtocontroltherobot.To
keeptheworkreasonableyouwillbegiventheArduinoprogramtorun(youneedtoreviewit
tobesureyouunderstandit,butthecodeisdone)andyouhavealreadyfinishedmostofthe
MATLABGUIDEprograminclass(
makingsliders
,DHarm).Ifyoufinishedalloftheinclass
workyouwillonlyneedtoaddtheserialcommunicationpartstotheGUI(wedidntdothatin
class).

Youshoulduse
your
MATLABGUIDEprogram.Howeveryoucan
review
mineifyougot
stuckinclass.Soyoucantjust
use
mine,butyoucanlookatthecodeasmuchasyouwant
toget
your
GUIDEprogramuptospeed.Hereismycode.

https://github.com/ME435/MATLABRobotArmGUIStart

Clickonthe
DownloadZip
buttonandextractthecontentsanywhereyoulike.Makethat
pathyourMATLABworkingfolder,then,ifyouneedtolookatmycode,opentheGUIDE
programbytyping:

> guide DhArm

YoucanrunmyGUItoseethefeaturesIadded.Itshouldlooksomethinglikethis.

Youareonlyrequiredtohavethe
5jointsliders
,the
jointanglesstatictex
t,the
gripper
slider
,the
connectionarea
,andthe
armpatchaxesthatmatchestherealrobot
.The
otherfeaturesIadded,the5greenbuttonsand3redbuttonstosetsavedpositionsare
optionalextras.AlsoIaddedanimagetoa
secondaxes
behindthemainaxestoshowthe
WildThumper.Notethatthe.pngimagehasalphavalues.Ifyouaddthatimagehereis
samplecodeyoullneedtorespectthealphaDataintheimage.

[imgData,map,alphaChannel] =
imread
(
'wildthumper.png'
);
imageObject =
image
(imgData,
'Parent'
, axesHandle,
'AlphaData'
, alphaChannel);

Ialsomodifiedlink0tohidethelargebasefaceandIaddedanXYZtodisplaythelocationof
thegrippertip.
Thoseextrasarentrequired.
Ijustlikeaddingfunthings.Addyourown
funextrasifyouhavetime.Imhappytogive110%againifyouthinkofafunfeaturebeyond
whatIadded.(lessformalthistime,noprettyrubric).

InadditiontotheMATLABsideoflifeweregoingtobemakinganewArduinoprojectand
usinga
new
library.Yesthatsright
ArmServos
isnowtheoldlibraryandwereusinga
newlibrary.:)Thenewlibraryiscalled
ArmServosSpeedControlled
(dontworryitsVERY
similar).Herearetheimportantfunctionswelluseinthispart.

ArmServosSpeedControlled
ArmServosSpeedControlled();
void setPosition(int joint1Angle, int joint2Angle, int joint3Angle, int joint4Angle,
int joint5Angle);
void updateServos(void);

The
ArmServosSpeedControlled
libraryisasubclassofthe
ArmServos
library.Soit
inheritsallmethodsfromArmServosandaddsafewmorenewandimprovedfeatures.You
willstillneedtousesomeArmServosmethodsthatdidntchange,suchas.
ArmServos
void attach();
void setGripperDistance(int distance);

Thedifferencebetweenthetwolibrariesissimple.WhenyousetapositioninArmServosthe
servoisgiventhefinaljointlocationandtriestogothereasfastaspossible.Thisresultsina
slightlyjerkylookingmoveanditcreatesaworsecasescenariofortheamountofcurrent
used.
ArmServosSpeedControlled
usesan
easeineaseout
mechanismtomovethe
jointssloweratthebeginningandendofthemove.Thislooksslightlylessjerky.Additionally
byslowingdownthatratethatJoint2moves(significantly)wereducetheworsecasecurrent
requirements(notabigissueforyou,butIliketobecareful).

ThereisminorcatchtousingArmServosSpeedControlled
The
ArmServosSpeedControlled
libraryrequiresyoutocallthe
updateServos
methodto
continuemovingthejoints.WithArmServosyousimplysetthepositionandyouweredone.
Itwaseasy.Nowyouneedtosettheposition,thencall
updateServos
regularlytomakethe
movementhappen.IdeallyyoudcallupdateServosatleastevery10mS.Additionallythe
libraryworksabitbetterifyouletthemovecompletebeforesendingnewpositioncommands
(littlebugthereIhaventfiguredoutyet:)).

Ifyourloopfunctionisfastyoucansimplyaddacall
updateServos
withintheloopfunction
andthatllworkgreat.ForexamplethisloopjustdoesacheckforSerialdataandupdatesthe
servos.Veryfastandworksgreattojustadd
updateServos
totheend(ideal).
void loop() {
// See if there is a new message from MATLAB.
if (Serial.available() > 0) {
robotCom.handleRxByte(Serial.read());
}
armServos.updateServos();

ItellyouallthisabouttheArmServosSpeedControlledlibrarybecauseIwantyouto
understanditsoyoucanuseitlater.HoweverforthispartIhaveanexampleforyourthatwill
workjustfine.Open
File>Examples>ArmServosSpeedControlled>MatlabRobotArm

YoudontneedtowriteanyArduinocode,justcompileanduploadthatexampleasis.Sorry
aboutgivingyouthespeechandgivingyoutheanswer.Illmakesuretoaskquestionson
theexamabouthowthelibraryworkstorewardyouforcarefulreadingandunderstandingthe
code.:)
Soldering
None.Youvealreadygotthearmready.

Code
OnArduinojustloadinthatexample.FornowIddisconnecttheservopowercableandjust
watchthemessagesontheLCD.Iftheywork,thenconnecttheservopower.Thatmakes
testingeasier.

BacktoMATLAB.RuntheyourGUI.Makesureitworks.Thenstartaddingserial
communication.YoucanlookatmyGUItoseesomeTODOsIaddedifyouthinkyouneed
morehelp.TherearethreemaintasksyoullneedtoaddtoyourGUI.

Threetasks:
Openaserialconnectiontotherobot.Addlayoutbuttons+edittextandbackitupinthe
.m.
Ifconnected,sendgrippercommandswhentheslidermoves.
Ifconnected,sendpositioncommandswhenanyjointslidermoves.

Notethatyourprogramshouldn'tcrashifyouclickonamovementcontrolwhenyouaren't
connected.Itshouldjustdisplayamessagetotheconsoleonly.

PersonallyIfindthisdemoprettyneat.Itsacoolwaytoseethephysicalrobotarmmatch
theDenavitHartenbergsimulation.IplayedwiththispartoflongerthanIdcaretoadmit.
YouwillneedtogetthispartcheckedoffbyDr.Fisher.Irecommendyoumakeavideo

YouarenowdonewithMATLABinthiscourse.FromhereonoutwereAndroidfolks!Yeah!
ForourfirstAndroidappweregoingtoUSEanapp.WellwriteAndroidappsinclassfirst
thendomore
appauthoringinthe
next
lab
.Letsmoveontothenextpartandtalkabout
theArmScriptsapp(thatyoumayhavealreadydownloadduringclass).

You might also like