robotarmmatlabgui.pdf
TRANSCRIPT
-
MATLABGUIfortherobotarmGoalThegoalofthisexerciseistouseyourMATLABGUIDEprogramtocontroltherobot.TokeeptheworkreasonableyouwillbegiventheArduinoprogramtorun(youneedtoreviewittobesureyouunderstandit,butthecodeisdone)andyouhavealreadyfinishedmostoftheMATLABGUIDEprograminclass(makingsliders,DHarm).IfyoufinishedalloftheinclassworkyouwillonlyneedtoaddtheserialcommunicationpartstotheGUI(wedidntdothatinclass).YoushoulduseyourMATLABGUIDEprogram.Howeveryoucanreviewmineifyougotstuckinclass.Soyoucantjustusemine,butyoucanlookatthecodeasmuchasyouwanttogetyourGUIDEprogramuptospeed.Hereismycode.
https://github.com/ME435/MATLABRobotArmGUIStartClickontheDownloadZipbuttonandextractthecontentsanywhereyoulike.MakethatpathyourMATLABworkingfolder,then,ifyouneedtolookatmycode,opentheGUIDEprogrambytyping:
> guide DhArm YoucanrunmyGUItoseethefeaturesIadded.Itshouldlooksomethinglikethis.
-
Youareonlyrequiredtohavethe5jointsliders,thejointanglesstatictext,thegripperslider,theconnectionarea,andthearmpatchaxesthatmatchestherealrobot.TheotherfeaturesIadded,the5greenbuttonsand3redbuttonstosetsavedpositionsareoptionalextras.AlsoIaddedanimagetoasecondaxesbehindthemainaxestoshowtheWildThumper.Notethatthe.pngimagehasalphavalues.IfyouaddthatimagehereissamplecodeyoullneedtorespectthealphaDataintheimage.
[imgData,map,alphaChannel] = imread('wildthumper.png'); imageObject = image(imgData, 'Parent', axesHandle, 'AlphaData', alphaChannel);
Ialsomodifiedlink0tohidethelargebasefaceandIaddedanXYZtodisplaythelocationofthegrippertip.Thoseextrasarentrequired.Ijustlikeaddingfunthings.Addyourownfunextrasifyouhavetime.Imhappytogive110%againifyouthinkofafunfeaturebeyondwhatIadded.(lessformalthistime,noprettyrubric).InadditiontotheMATLABsideoflifeweregoingtobemakinganewArduinoprojectandusinganewlibrary.YesthatsrightArmServosisnowtheoldlibraryandwereusinganewlibrary.:)ThenewlibraryiscalledArmServosSpeedControlled(dontworryitsVERYsimilar).Herearetheimportantfunctionswelluseinthispart.
ArmServosSpeedControlled ArmServosSpeedControlled(); void setPosition(int joint1Angle, int joint2Angle, int joint3Angle, int joint4Angle,
int joint5Angle); void updateServos(void);
TheArmServosSpeedControlledlibraryisasubclassoftheArmServoslibrary.SoitinheritsallmethodsfromArmServosandaddsafewmorenewandimprovedfeatures.YouwillstillneedtousesomeArmServosmethodsthatdidntchange,suchas.
ArmServos void attach(); void setGripperDistance(int distance);
Thedifferencebetweenthetwolibrariesissimple.WhenyousetapositioninArmServostheservoisgiventhefinaljointlocationandtriestogothereasfastaspossible.Thisresultsinaslightlyjerkylookingmoveanditcreatesaworsecasescenariofortheamountofcurrentused.ArmServosSpeedControlledusesaneaseineaseoutmechanismtomovethejointssloweratthebeginningandendofthemove.Thislooksslightlylessjerky.AdditionallybyslowingdownthatratethatJoint2moves(significantly)wereducetheworsecasecurrentrequirements(notabigissueforyou,butIliketobecareful).
-
ThereisminorcatchtousingArmServosSpeedControlledTheArmServosSpeedControlledlibraryrequiresyoutocalltheupdateServosmethodtocontinuemovingthejoints.WithArmServosyousimplysetthepositionandyouweredone.Itwaseasy.Nowyouneedtosettheposition,thencallupdateServosregularlytomakethemovementhappen.IdeallyyoudcallupdateServosatleastevery10mS.Additionallythelibraryworksabitbetterifyouletthemovecompletebeforesendingnewpositioncommands(littlebugthereIhaventfiguredoutyet:)).IfyourloopfunctionisfastyoucansimplyaddacallupdateServoswithintheloopfunctionandthatllworkgreat.ForexamplethisloopjustdoesacheckforSerialdataandupdatestheservos.VeryfastandworksgreattojustaddupdateServostotheend(ideal).
void loop() { // See if there is a new message from MATLAB. if (Serial.available() > 0) { robotCom.handleRxByte(Serial.read()); } armServos.updateServos(); }
ItellyouallthisabouttheArmServosSpeedControlledlibrarybecauseIwantyoutounderstanditsoyoucanuseitlater.HoweverforthispartIhaveanexampleforyourthatwillworkjustfine.OpenFile>Examples>ArmServosSpeedControlled>MatlabRobotArmYoudontneedtowriteanyArduinocode,justcompileanduploadthatexampleasis.Sorryaboutgivingyouthespeechandgivingyoutheanswer.Illmakesuretoaskquestionsontheexamabouthowthelibraryworkstorewardyouforcarefulreadingandunderstandingthecode.:) SolderingNone.Youvealreadygotthearmready.CodeOnArduinojustloadinthatexample.FornowIddisconnecttheservopowercableandjustwatchthemessagesontheLCD.Iftheywork,thenconnecttheservopower.Thatmakestestingeasier.BacktoMATLAB.RuntheyourGUI.Makesureitworks.Thenstartaddingserialcommunication.YoucanlookatmyGUItoseesomeTODOsIaddedifyouthinkyouneedmorehelp.TherearethreemaintasksyoullneedtoaddtoyourGUI.
-
Threetasks: Openaserialconnectiontotherobot.Addlayoutbuttons+edittextandbackitupinthe
.m. Ifconnected,sendgrippercommandswhentheslidermoves. Ifconnected,sendpositioncommandswhenanyjointslidermoves.
Notethatyourprogramshouldn'tcrashifyouclickonamovementcontrolwhenyouaren'tconnected.Itshouldjustdisplayamessagetotheconsoleonly.PersonallyIfindthisdemoprettyneat.ItsacoolwaytoseethephysicalrobotarmmatchtheDenavitHartenbergsimulation.IplayedwiththispartoflongerthanIdcaretoadmit.YouwillneedtogetthispartcheckedoffbyDr.Fisher.IrecommendyoumakeavideoYouarenowdonewithMATLABinthiscourse.FromhereonoutwereAndroidfolks!Yeah!ForourfirstAndroidappweregoingtoUSEanapp.WellwriteAndroidappsinclassfirstthendomoreappauthoringinthenextlab.LetsmoveontothenextpartandtalkabouttheArmScriptsapp(thatyoumayhavealreadydownloadduringclass).