You are on page 1of 45

Motors, Control

Agenda for today

This talk:
Motor

Basics

PWM, Encoders, Servos, etc.

Ro

ot Control Strategies !sing the "RC AP#

"$en %a
Ro

ot rolling Re&ote control #ntegrate a sensor Work to'ards (riday check$oint

Re&inder: (riday)s Check$oint

Ro ot sho*ld e $*t together


Te&$orary

$eg+ oard fine ,on)t need a target+collecting &echanis&

Ro ot sho*ld e controlla le y re&ote, *sing color coded cards


See

Wiki for details

-ave a $lan.strategy for contest


/ri$$er

&echanis&0 Way$oint 1de&onstration2

Motors+ Physics

Motor 'indings have a fi3ed resistance 4ignoring heating5 6oltage differential on &otor leads ca*ses c*rrent to flo'. 4"h&)s la'5 Magnetic field $ro$ortional to c*rrent Tor7*e $ro$ortional to &agnetic field strength 4and th*s c*rrent5 Tor7*e ca*ses rotor to egin rotating.
Which

'ay0 #t tries to reduce the &agnetic field strength.

Motors+ Physics 4contin*ed5

4Magnetic5 Rotor is no' t*rning


(araday)s

%a' a$$lies. A voltage is generated8


Which 'ay0 To reduce the &agnetic field strength 9: to red*ce the c*rrent 9: cancelling o*t the e3ternally+a$$lied voltage

Motor 6oltage 9 A$$lied voltage ; Back EM(


This

is the voltage 'e *sed 'hen deter&ining ho' &*ch c*rrent flo's

Motors+ Physics 4contin*ed5


Scenario: &otor <*st t*rned on


Back Back Back

EM( 9 =, c*rrent is 6in.R EM( 9 =, c*rrent is 6in.R

Scenario: &otor rotor is stalled Scenario: &otor rotating *ni&$eded


EM( 9 + 6in, c*rrent is = 4With friction, c*rrent is non+>ero *t s&all.5

Scenario: a$$lied voltage changes $olarity fro& ?6in to +6in


Back

EM( 9 +6in 4inertia85, c*rrent is @6in.R

Motors as #nd*ctors
Another co&$lication: &otors 'indings are ind*ctors #nd*ctors o$$ose changes in c*rrent

They

store energy When c*rrent 'o*ld other'ise change, ind*ctors eco&e voltage so*rces s*ch that the c*rrent re&ains constant

69%d#.dt

Motors as #nd*ctors 4contin*ed5


69%d#.dt Scenario: yo* *n$l*g a r*nning &otor


dt

9= d#.dt 9 infinity This &akes 6 1really ig2 Makes a ig s$ark so that dt isn)t 7*ite =

Scenario: yo* ra$idily change the e3ternal voltage


d#.dt

9 very large 4finite s'itching ti&es5 6 very ig.

Motor Physics+ Take ho&e lessons


,on)t *n$l*g a r*nning &otor ,on)t ra$idly change the voltage on a &otorA slo'ly increase.decrease it to avoid a c*rrent s$ike
When

accelerating, accelerate in a co*$le ste$s: @BC for D= &s, B=C for D=&s, EBC for D=&s, then F==C. This goes for changing direction and decelerating too8 Go*r 'heels are less likely to sli$ too8

Po'ering Motors

CP! can)t control directly


*P

$ins *s*ally can so*rce.sink H F=&A $ins are 1F2s and 1=2s

"*r &otors can *se @==&A or &ore8

*P

There is no 1+F2, so no 1 ack'ards2 There is no 1=.B2, so no 1&edi*& s$eed2

We 'ant these things8 -o' do 'e do it0

Motors: -+ ridges
Vmotor

Motor

-+ ridge allo's idirectional control A I , on: for'ard C I B on: ack'ards A I B on or C I , on: horri le8 "*r -+ ridges have direction ? ena le What 'o*ld B I , on do0

Motors: PWM
-o' do 'e r*n at fractional $o'er0 Consider ra$idly toggling -+ ridge on I off

JBC $o'er0 K=C $o'er0

K=C $o'er0

Motors: PWM contin*ed

T'o degrees of freedo&: $eriod and d*ty cycle


Period

T'o degrees of freedo&: $eriod and d*ty cycle 4$ercentage 1on25

PWM+ Why does this 'ork0


Why does a B=C d*ty cycle look like half the voltage0 #t doesn)tL not al'ays, at least:

Scenario:

$eriod9F day, d*ty cycle9=.B.

Motor 'ill r*n f*ll last for F@ ho*rs, then sto$ for F@ ho*rs

PWM+ ho' to chose $eriod0

Rotor.Magnets have a &echanical ti&e constant


A&o*nt

of ti&e it takes for rotor to achieve MD.@C of its final velocity after a ste$ in$*t.

Motor 'indings 4ind*ctor5 and resistance have electrical ti&e constant


A&o*nt

of ti&e it takes for c*rrent to achieve MD.@C of its final val*e after a ste$ in$*t with rotor locked in position.

Motor drivers take ti&e to s'itch. #f $eriod is too short, drivers 'ill s$end the 'hole ti&e s'itching and not cond*cting 9: lo' efficiency.

PWM+ ho' to choose $eriod0


Mechanical ti&e constant N F= &sec Electrical ti&e constant: N F &sec PWM must e faster than &ech ti&e constant, or &otor 'ill vi rate (aster than electrical ti&e constant ens*res PWM 'avefor& is effectively an analog voltage
Why

do 'e care0

Avoid fre7*encies H @=O-> d*e to h*&an hearing8 4&agnetostriction5 Avoid fre7*encies : driver s'itching fre7*ency 4NF==O->05

Motor $erfor&ance &eas*re&ent

-o' do 'e find o*t ho' a &otor is $erfor&ing0


C*rrent Sensing Back EM( 4tricky85 Tacho&eter Encoders

C*rrent Sensing
Tells yo* ho' &*ch torque the &otor is $rod*cing. Pot directly related to angular velocity

,e$endent

on terrain8

Back EM(

!se Back EM( to &eas*re s$eed


C*rrent

&*st e >ero

M*st disconnect $o'er and 'ait8 4a co*$le electrical ti&e constants5 "RC oard can &eas*re, *t re7*ires great care and s$ecial ca le.

Tacho&eter
Add an additional little &otor to the o*t$*t shaft 'ith very lo' inertia This &otor generates a ack EM( This voltage $ro$ortional to rotational velocity.

Si&$le Encoders

Attach a disk to the &otor shaft and attach a reak+ ea& sensor across the teeth.

time

"*t$*t of Encoder

"r, *se a reflectivity sensor and a disk 'ith lack I 'hite colored 'edges. Are 'e going for'ards or ack'ards0

Q*adrat*re Phase Encoders

!se TW" single encoders, R= degrees o*t of $hase. Close+*$ of teeth

time

time

(or'ard

Back'ard

(or'ard and ack'ard are no' disting*isha le8

Servo Motors

Servo &otors seek and hold a s$ecific angle a*to&atically8 -ave integrated gearhead I control electronics !se PWM as interface8

-*h0

A o*t FJ= degrees of rotation, to 'ithin NF degree Pretty good tor7*e, *t take it easy on the&8

Po'er dissi$ation can e ad Plastic gears are 'i&$y #nter&ittent d*ty only

Servo Motors, contin*ed


PWM is not *sed in the sa&e 'ay as nor&al &otors. Servo *ses PWM to *ild an analog voltage that is co&$ared to a $otentio&eter on the o*t$*t 4feed ack5. S*st send a PWM 'ith a d*ty cycle $ro$ortional to the desired angle8 P*lse 'idths that are too short.long ca*se servo to shake violently8
Pot

very good for the&. Cons*&es a lot of $o'er

"ther Act*ators

"ther act*ators yo* &ight consider:


Solenoids M*scle Wire Chea$ si&$le ,C &otors 4B or F@65 Electro&agnetic Hso&ething: An act*ator ? a s$ring is a different act*ator !se &echanical advantages 'hen yo* can: levers, $*lleys, ra&$s, 'inches Servos have a fair a&o*nt of tor7*e for a &otor their si>e, *t can easily e over'orked8 ,esign so that act*ators e3$end $o'er only intermittently!

,on)t forget J.=F


Ro ot Control Strategies
-o' do yo* &ake yo*r ro ot do 'hat yo* 'ant0 Co&&on design: *ild ehaviors, then coordinate ehaviors fro& a 1$lanner2

Control Logic

Turn

Go Straight

Follow Wall

Close Claw

Control Strategies

(i3ed Plan 4Scri$ted5

Pre$rogra& a n*& er of o$erations or $hases 'hich 'ill r*n in a fi3ed se7*ence

Can)t co$e 'ell 'ith the *ne3$ected8

(inite State Machine


Pre$rogra& a n*& er of contingencies

E.g., #f #)& looking for a target and # hit a 'all, t*rn right.

Presents so&e a ility to co$e 'ith the *n*s*al B*t still can)t co$e 'ith things you haven)t considered

A# Planner

Consider all $ossi le 1$lans2 4se7*ence of actions5


/ive each one a 1score2 Pick the est one

Might e a le to fig*re a 'ay o*t of a ind that yo* hadn)t considered. Co&$licated, so&eti&es slo'. Assigning scores to agree 'ith ho' yo* 'o*ld decide can e really hard.

Control Strategies

-y rid
Co&

ine the a ove

E3a&$le: (i3ed $lan ? (inite State Machines


(or

the first &in*te, r*n the 1find a target2 (SM (or the second &in*te, r*n the 1search for and go to a scoring area2 Release the target (or the third &in*te, try to go ho&e

Philoso$hy of Control

Ono' Everything

1My c*rrent $osition is 4@.M,D.E5, #)& facing e3actly east. There)s a target ehind &e at 4F.B,D.M5 and a 'all et'een *s. The follo'ing series of $recise &oves 'ill get &e there.2 Ro ot &aintains a lot of state 4infor&ation a o*t the 'orld5

6ery easy to e 'rong a o*t so&e of it

Very $o'erf*l. Very hard. 1/ee, /eorge. That s*re is a $retty target over there. M&&&, $retty red color. # sho*ld go there.2 4LlaterL5 1Ah, # have a red thing. # feel ha$$y. B*t #)d feel ha$$ier if # sa' so&e yello' right a o*t no'L so #)ll s$in82 Pot &*ch state to &aintain.

Ono' Pothing

-ard to e 'rong8 -ard to &ake good decisions.

Philoso$hy of Control 4contin*ed5

Go* 'ant to e so&e'here in the &iddle. (or e3a&$le:


Maintain

as &*ch state as yo* can, *t *nderstand the &argin of errors in yo*r state and take this into acco*nt. E3$ect to e 'rong. Maintain only a little state. ,o lots of 'andering, *t try to re&e& er 'here yo*)ve e3$lored so yo* &a3i&i>e the gro*nd yo*)ve covered. /ather infor&ation a o*t $artic*lar $laces. When yo* get to one, kno' ho' to recogni>e it. Then fig*re o*t 'hat the ne3t fe' things yo* sho*ld try to do are. As yo* 'ander, yo*)ll get lostA ada$t and si&$lify yo*r $lan ased on what goes 'rong.

B*ilding Behaviors

-o' 'o*ld yo* *ild a right+'all follo'er0 (inite State Machine

E3a&$le:
F. @. D.

#f #)& getting farther a'ay fro& the 'all, t*rn a *nit to the right #f #)& too close to the 'all, t*rn a *nit to the left /o for'ard a it, then ack to ste$ F.

Easy to 'rite, easy to *nderstand Pot terri ly fle3i le

What if 'e)re getting farther a'ay fro& the 'all 4a 'heel is sli$$ing, for e3a&$le5 faster than 'e are t*rning to the right0

B*ilding Behaviors+ Wall (ollo'er

!se a feed ack+ ased control syste&


E3a&$le:

Co&$*te error9distance fro& 'all ; desired distance fro& 'all


ErrorH=: too close Error:=: too far a'ay

Co&$*te so&e f*nction of error, and *se this to deter&ine ho' shar$ly 4and in 'hat direction5 to t*rn.

Rich

&athe&atics availa le to hel$ design Ro *st in theory, a it tricky to $erfect in $ractice


Potential for insta ility 9: a&*se&ent for a*dience
(4error5

often has derivative and integral co&$onents 4P#, control5

P#, control

#f yo*)re really far a'ay fro& the 'all, t*rn shar$ly. #f yo*)re only slightly veering, t*rn <*st a it.

That)s Pro$ortional

#f yo*)re ra$idly getting farther a'ay fro& the 'all, start t*rning harder.

That)s ,erivative

#f, des$ite yo*r efforts, yo* kee$ getting farther a'ay for a long ti&e, start t*rning harder.

That)s #ntegral

T*rnrate9C$e ? Ci Te ? Cdde.dt ,iscrete+ti&e calc*l*s This is act*ally 'hat a servo &otor does to hold a $artic*lar angle

!sing the "RC AP#


#)& al&ost done talkingL Where is the "RC li rary0

%ook on the cs==)s P(S server

Patches co&e o*t $eriodically. Each version is ti&e sta&$ed. E.g., orc=F=J=D.tg>. Co$y it so&e'here *sef*l !ntar it 4tar ;3>vf orc=F=J=D.tg>5 Edit.co$y the hello'orld e3a&$le to get started 7*ickly

What do # do 'ith it0


AP# availa le fro& the Wiki


%argely self e3$lanatory #t)s 'orth sitting do'n and reading thro*gh

"RC AP# ,oc*&entation

/etting started
Go*

&*st call orcUinitiali>e45 efore anything else. Go* &*st link 'ith li orc.a after yo*r .o files
E.g.: g?? ;o &y$rogra& &ain.o li orc.a !se g??, not gcc

"RC Co&&*nication

Band'idth very li&ited


"nly

a co*$le h*ndred transactions $er second Starvation8 Consider caching res*lts

%atency very high


Single

transaction can take :F=&s %ost o$$ort*nity for co&$*tation Consider doing co&&*nication asynchronously or heavy co&$*tation in se$arate thread.

%C, co&&ands

AP#:
orcUlcd-o&e orcUlcdPrint, orcUlcd/oto

orcUlcdPrintf

%C, screen is only FM3@ characters8

Analog Co&&and

AP#:
orcUanalog orcUanalogSetResol*tion orcUanalogSetMa3Port orcUc*rrentSense

Analog val*es are V=,MBBDBW corres$onding to V=,BW volts.

,igital Co&&ands

AP#
orcU

*ttons, orcU *ttonsWait orcUdigitalRead orcUdigitalWrite orcUdigitalSet,irection

"RC s*$$orts digital out, *t this is dangero*s


#f

yo* $l*g in sensor that o*t$*ts a val*e into a digital o*t $ort, yo* can da&age yo*r "RC. Ask a TA if yo* need this, and al'ays e caref*l8

Motor Co&&ands

AP#:
orcU&otorPWM orcU&otor,ir

Motors are inde3ed VF,KW; different than other $orts 'hich are V=,3W8 !se sy& olic directions: MOTOR_FORWARD
MOTOR_R!V!RS! MOTOR_BRA"!
These

&ay not corres$ond to 1for'ard2.2 ack'ard2 for yo*r ro ot Motors have different strengths for'ard and ack'ard

Servo Co&&ands

AP#:
orcUservoPWM orcUservoSetProfile orcUservoSeek hitecD==$rofile

Servos sho*ld not e seeked o*t of range for e3tended $eriods of ti&e 4:@ seconds05 Servos s*$$ort profiles, allo'ing yo* to s$ecify an angle, rather than a $*lse 'idth.
P*rely

a convenience f*nctionA <*st calls servoPWM.

!ltraso*nd Co&&ands

AP#:
orcU*ltraso*ndPing orcU*ltraso*ndRead

Can only *se one *ltraso*nd at a ti&e M*st 'ait for the sonar to echo efore reading8

Batteries: Care and (eeding


F@6 %ead Acid Battery, B Ah Battery recharges 'henever "RC is $l*gged into AC I attery is connected Recharging attery can *se lots of c*rrent
,on)t

dee$ly discharge attery. #t)s ad for it any'ay8 ,isconnect geode if reg*lator gets hot
That frees *$ =.EA for attery charging8
#f

reg*lator still too hot, disconnect attery. Recharge 'ith a ench s*$$ly.

Soldering #ron Care


#&&ediately tin 4cover 'ith solder5 ne' ti$s. When soldering, if ti$ isn)t shiny, it needs to e cleaned
S$onge Re+tin

'ith solder, or retinning goo$

Oee$ solder on ti$ 'hen storing to $revent o3idation of ti$ Pever, ever, shar$en the ti$8
Ti$

it8

has s$ecial alloy on o*ter coating. ,on)t re&ove

#)& done talking8


Po' get to 'ork8 Pot s*re 'here to start0

Talk

to yo*r advisor8

You might also like