You are on page 1of 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