Motors, Control, API - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

Motors, Control, API

Description:

Motor windings have a fixed resistance (ignoring heating) ... an analog voltage that is compared to a potentiometer on the output (feedback) ... – PowerPoint PPT presentation

Number of Views:137
Avg rating:3.0/5.0
Slides: 46
Provided by: edwin2
Category:

less

Transcript and Presenter's Notes

Title: Motors, Control, API


1
Motors, Control, API
  • 6.186, January 2003
  • Edwin Olson

2
Agenda for today
  • This talk
  • Motor Basics
  • PWM, Encoders, Servos, etc.
  • Robot Control Strategies
  • Using the ORC API
  • Open Lab
  • Robot rolling
  • Remote control
  • Integrate a sensor
  • Work towards Friday checkpoint

3
Reminder Fridays Checkpoint
  • Robot should be put together
  • Temporary peg-board fine
  • Dont need a target-collecting mechanism
  • Robot should be controllable by remote, using
    color coded cards
  • See Wiki for details
  • Have a plan/strategy for contest
  • Gripper mechanism?
  • Waypoint demonstration

4
Motors- Physics
  • Motor windings have a fixed resistance (ignoring
    heating)
  • Voltage differential on motor leads causes
    current to flow. (Ohms law)
  • Magnetic field proportional to current
  • Torque proportional to magnetic field strength
    (and thus current)
  • Torque causes rotor to begin rotating.
  • Which way? It tries to reduce the magnetic field
    strength.

5
Motors- Physics (continued)
  • (Magnetic) Rotor is now turning
  • Faradays Law applies.
  • A voltage is generated!
  • Which way? To reduce the magnetic field strength
    gt to reduce the current gt cancelling out the
    externally-applied voltage
  • Motor Voltage Applied voltage Back EMF
  • This is the voltage we used when determining how
    much current flows

6
Motors- Physics (continued)
  • Scenario motor just turned on
  • Back EMF 0, current is Vin/R
  • Scenario motor rotor is stalled
  • Back EMF 0, current is Vin/R
  • Scenario motor rotating unimpeded
  • Back EMF - Vin, current is 0
  • (With friction, current is non-zero but small.)
  • Scenario applied voltage changes polarity from
    Vin to -Vin
  • Back EMF -Vin (inertia!), current is 2Vin/R

7
Motors as Inductors
  • Another complication motors windings are
    inductors
  • Inductors oppose changes in current
  • They store energy
  • When current would otherwise change, inductors
    become voltage sources such that the current
    remains constant
  • VLdI/dt

8
Motors as Inductors (continued)
  • VLdI/dt
  • Scenario you unplug a running motor
  • dt 0
  • dI/dt infinity
  • This makes V really big
  • Makes a big spark so that dt isnt quite 0
  • Scenario you rapidily change the external
    voltage
  • dI/dt very large (finite switching times)
  • V very big.

9
Motor Physics- Take home lessons
  • Dont unplug a running motor
  • Dont rapidly change the voltage on a motor
    slowly increase/decrease it to avoid a current
    spike
  • When accelerating, accelerate in a couple steps
    25 for 30 ms, 50 for 30ms, 75 for 30ms, then
    100.
  • This goes for changing direction and decelerating
    too!
  • Your wheels are less likely to slip too!

10
Powering Motors
  • CPU cant control directly
  • uP pins usually can source/sink lt 10mA
  • Our motors can use 200mA or more!
  • uP pins are 1s and 0s
  • There is no -1, so no backwards
  • There is no 0.5, so no medium speed
  • We want these things!
  • How do we do it?

11
Motors H-bridges
  • H-bridge allows bidirectional control
  • A D on forward
  • C B on backwards
  • A B on or
  • C D on horrible!
  • Our H-bridges have direction enable
  • What would B D on do?

12
Motors PWM
  • How do we run at fractional power?
  • Consider rapidly toggling H-bridge on off

85 power?
40 power?
40 power?
13
Motors PWM continued
  • Two degrees of freedom period and duty cycle
  • Two degrees of freedom period and duty cycle
    (percentage on)

14
PWM- Why does this work?
  • Why does a 50 duty cycle look like half the
    voltage?
  • It doesnt not always, at least
  • Scenario period1 day, duty cycle0.5.
  • Motor will run full blast for 12 hours, then stop
    for 12 hours

15
PWM- how to chose period?
  • Rotor/Magnets have a mechanical time constant
  • Amount of time it takes for rotor to achieve
    63.2 of its final velocity after a step input.
  • Motor windings (inductor) and resistance have
    electrical time constant
  • Amount of time it takes for current to achieve
    63.2 of its final value after a step input with
    rotor locked in position.
  • Motor drivers take time to switch. If period is
    too short, drivers will spend the whole time
    switching and not conducting gt low efficiency.

16
PWM- how to choose period?
  • Mechanical time constant 10 msec
  • Electrical time constant 1 msec
  • PWM must be faster than mech time constant, or
    motor will vibrate
  • Faster than electrical time constant ensures PWM
    waveform is effectively an analog voltage
  • Why do we care?
  • Avoid frequencies lt 20KHz due to human hearing!
    (magnetostriction)
  • Avoid frequencies gt driver switching frequency
    (100KHz?)

17
Motor performance measurement
  • How do we find out how a motor is performing?
  • Current Sensing
  • Back EMF (tricky!)
  • Tachometer
  • Encoders

18
Current Sensing
  • Tells you how much torque the motor is producing.
  • Not directly related to angular velocity
  • Dependent on terrain!

19
Back EMF
  • Use Back EMF to measure speed
  • Current must be zero
  • Must disconnect power and wait! (a couple
    electrical time constants)
  • ORC board can measure, but requires great care
    and special cable.

20
Tachometer
  • Add an additional little motor to the output
    shaft with very low inertia
  • This motor generates a back EMF
  • This voltage proportional to rotational velocity.

21
Simple Encoders
  • Attach a disk to the motor shaft and attach a
    break-beam sensor across the teeth.

Output of Encoder
  • Or, use a reflectivity sensor and a disk with
    black white colored wedges.
  • Are we going forwards or backwards?

22
Quadrature Phase Encoders
  • Use TWO single encoders, 90 degrees out of phase.

Close-up of teeth
Forward
Backward
  • Forward and backward are now distinguishable!

23
Servo Motors
  • Servo motors seek and hold a specific angle
    automatically!
  • Have integrated gearhead control electronics
  • Use PWM as interface!
  • Huh?
  • About 180 degrees of rotation, to within 1
    degree
  • Pretty good torque, but take it easy on them!
  • Power dissipation can be bad
  • Plastic gears are wimpy
  • Intermittent duty only

24
Servo Motors, continued
  • PWM is not used in the same way as normal motors.
  • Servo uses PWM to build an analog voltage that is
    compared to a potentiometer on the output
    (feedback).
  • Just send a PWM with a duty cycle proportional to
    the desired angle!
  • Pulse widths that are too short/long cause servo
    to shake violently!
  • Not very good for them.
  • Consumes a lot of power

25
Other Actuators
  • Other actuators you might consider
  • Solenoids
  • Muscle Wire
  • Cheap simple DC motors (5 or 12V)
  • Electromagnetic ltsomethinggt
  • An actuator a spring is a different actuator
  • Dont forget 8.01
  • Use mechanical advantages when you can levers,
    pulleys, ramps, winches
  • Servos have a fair amount of torque for a motor
    their size, but can easily be overworked!
  • Design so that actuators expend power only
    intermittently!

26
Robot Control Strategies
  • How do you make your robot do what you want?
  • Common design build behaviors, then coordinate
    behaviors from a planner

27
Control Strategies
  • Fixed Plan (Scripted)
  • Preprogram a number of operations or phases which
    will run in a fixed sequence
  • Cant cope well with the unexpected!
  • Finite State Machine
  • Preprogram a number of contingencies
  • E.g., If Im looking for a target and I hit a
    wall, turn right.
  • Presents some ability to cope with the unusual
  • But still cant cope with things you havent
    considered
  • AI Planner
  • Consider all possible plans (sequence of
    actions)
  • Give each one a score
  • Pick the best one
  • Might be able to figure a way out of a bind that
    you hadnt considered.
  • Complicated, sometimes slow. Assigning scores to
    agree with how you would decide can be really
    hard.

28
Control Strategies
  • Hybrid
  • Combine the above
  • Example Fixed plan Finite State Machines
  • For the first minute, run the find a target FSM
  • For the second minute, run the search for and go
    to a scoring area
  • Release the target
  • For the third minute, try to go home

29
Philosophy of Control
  • Know Everything
  • My current position is (2.6,3.7), Im facing
    exactly east. Theres a target behind me at
    (1.5,3.6) and a wall between us. The following
    series of precise moves will get me there.
  • Robot maintains a lot of state (information about
    the world)
  • Very easy to be wrong about some of it
  • Very powerful. Very hard.
  • Know Nothing
  • Gee, George. That sure is a pretty target over
    there. Mmmm, pretty red color. I should go
    there. (later) Ah, I have a red thing. I feel
    happy. But Id feel happier if I saw some yellow
    right about now so Ill spin!
  • Not much state to maintain.
  • Hard to be wrong!
  • Hard to make good decisions.

30
Philosophy of Control (continued)
  • You want to be somewhere in the middle. For
    example
  • Maintain as much state as you can, but understand
    the margin of errors in your state and take this
    into account. Expect to be wrong.
  • Maintain only a little state. Do lots of
    wandering, but try to remember where youve
    explored so you maximize the ground youve
    covered.
  • Gather information about particular places. When
    you get to one, know how to recognize it. Then
    figure out what the next few things you should
    try to do are. As you wander, youll get lost
    adapt and simplify your plan based on what goes
    wrong.

31
Building Behaviors
  • How would you build a right-wall follower?
  • Finite State Machine
  • Example
  • If Im getting farther away from the wall, turn a
    unit to the right
  • If Im too close to the wall, turn a unit to the
    left
  • Go forward a bit, then back to step 1.
  • Easy to write, easy to understand
  • Not terribly flexible
  • What if were getting farther away from the wall
    (a wheel is slipping, for example) faster than we
    are turning to the right?

32
Building Behaviors- Wall Follower
  • Use a feedback-based control system
  • Example
  • Compute errordistance from wall desired
    distance from wall
  • Errorlt0 too close
  • Errorgt0 too far away
  • Compute some function of error, and use this to
    determine how sharply (and in what direction) to
    turn.
  • Rich mathematics available to help design
  • Robust in theory, a bit tricky to perfect in
    practice
  • Potential for instability gt amusement for
    audience
  • F(error) often has derivative and integral
    components (PID control)

33
PID control
  • If youre really far away from the wall, turn
    sharply. If youre only slightly veering, turn
    just a bit.
  • Thats Proportional
  • If youre rapidly getting farther away from the
    wall, start turning harder.
  • Thats Derivative
  • If, despite your efforts, you keep getting
    farther away for a long time, start turning
    harder.
  • Thats Integral
  • TurnrateCpe Ci ?e Cdde/dt
  • Discrete-time calculus
  • This is actually what a servo motor does to hold
    a particular angle

34
Using the ORC API
  • Im almost done talking
  • Where is the ORC library?
  • Look on the cs00s NFS server
  • Patches come out periodically. Each version is
    time stamped. E.g., orc010803.tgz.
  • What do I do with it?
  • Copy it somewhere useful
  • Untar it (tar xzvf orc010803.tgz)
  • Edit/copy the helloworld example to get started
    quickly
  • API available from the Wiki
  • Largely self explanatory
  • Its worth sitting down and reading through

35
ORC API Documentation
  • Getting started
  • You must call orc_initialize() before anything
    else.
  • You must link with liborc.a after your .o files
  • E.g. g o myprogram main.o liborc.a
  • Use g, not gcc

36
ORC Communication
  • Bandwidth very limited
  • Only a couple hundred transactions per second
  • Starvation!
  • Consider caching results
  • Latency very high
  • Single transaction can take gt10ms
  • Lost opportunity for computation
  • Consider doing communication asynchronously or
    heavy computation in separate thread.

37
LCD commands
  • API
  • orc_lcdHome
  • orc_lcdPrint, orc_lcdPrintf
  • orc_lcdGoto
  • LCD screen is only 16x2 characters!

38
Analog Command
  • API
  • orc_analog
  • orc_analogSetResolution
  • orc_analogSetMaxPort
  • orc_currentSense
  • Analog values are 0,65535 corresponding to
    0,5 volts.

39
Digital Commands
  • API
  • orc_buttons, orc_buttonsWait
  • orc_digitalRead
  • orc_digitalWrite
  • orc_digitalSetDirection
  • ORC supports digital out, but this is dangerous
  • If you plug in sensor that outputs a value into a
    digital out port, you can damage your ORC.
  • Ask a TA if you need this, and always be careful!

40
Motor Commands
  • API
  • orc_motorPWM
  • orc_motorDir
  • Motors are indexed 1,4 different than other
    ports which are 0,x!
  • Use symbolic directions MOTOR_FORWARD,
    MOTOR_REVERSE, MOTOR_BRAKE
  • These may not correspond to forward/backward
    for your robot
  • Motors have different strengths forward and
    backward

41
Servo Commands
  • API
  • orc_servoPWM
  • orc_servoSetProfile
  • orc_servoSeek
  • hitec300profile
  • Servos should not be seeked out of range for
    extended periods of time (gt2 seconds?)
  • Servos support profiles, allowing you to specify
    an angle, rather than a pulse width.
  • Purely a convenience function just calls
    servoPWM.

42
Ultrasound Commands
  • API
  • orc_ultrasoundPing
  • orc_ultrasoundRead
  • Can only use one ultrasound at a time
  • Must wait for the sonar to echo before reading!

43
Batteries Care and Feeding
  • 12V Lead Acid Battery, 5 Ah
  • Battery recharges whenever ORC is plugged into AC
    battery is connected
  • Recharging battery can use lots of current
  • Dont deeply discharge battery. Its bad for it
    anyway!
  • Disconnect geode if regulator gets hot
  • That frees up 0.7A for battery charging!
  • If regulator still too hot, disconnect battery.
    Recharge with a bench supply.

44
Soldering Iron Care
  • Immediately tin (cover with solder) new tips.
  • When soldering, if tip isnt shiny, it needs to
    be cleaned
  • Sponge
  • Re-tin with solder, or retinning goop
  • Keep solder on tip when storing to prevent
    oxidation of tip
  • Never, ever, sharpen the tip!
  • Tip has special alloy on outer coating. Dont
    remove it!

45
Im done talking!
  • Now get to work!
  • Not sure where to start?
  • Talk to your advisor!
Write a Comment
User Comments (0)
About PowerShow.com