Upload
douglas-lewis
View
218
Download
1
Embed Size (px)
Citation preview
Software Design Narrative
Self-Balancing Biped Robot
Seongwoon KoAnkith Cherala
Jinliang WeiKelton Stefan
Design Considerations
Main Function Flow Chart
Code Modules
Hierarchical Arrangement of Code Modules
Biped Control GUI
Outline
14 KB RAM, 512 KB Flash – large enough
Language: Embedded C◦ Compiler takes care of where to put variables and
code.
Explicitly Put into Flash (declared as const)◦ Look-up tables for trigonometric functions◦ Vector arrays of foot positions for static sub-
actions (later)
Design Considerations - Memory
8 PWM channels to control 8 servos
Problem: not fully utilize the duty resolution◦ Servo refresh period: 25 ms◦ Pulse width 0.6 ms ~ 2.4 ms controls 0 ~ 180
degrees of turning◦ Only use 7.2 % of the duty register resolution◦ Not accurate enough
Integrated Peripherals – PWM
Solution:◦ Set PWM period to 2.5 ms◦ 1 servo refresh period consists of 10 PWM periods◦ Set PWM duty register only for the first period, set
others to 0 (timer is used)
Integrated Peripherals – PWM(cont)
Connected to WiFly card for communicating with control GUI
Interrupt-driven receive◦ Not know when user will send command
Program-driven write◦ Send status message to user periodically
Integrated Peripherals - SCI
Connected to accelerometer for measuring external force.
Micro as master, accelerometer as slave
Interrupt-driven◦ Needs to take immediate action for external force
for balancing
Integrated Peripherals - SPI
1 ATD channel connected to ultrasonic range finder to detect obstacles
Program-driven◦ Checks output periodically◦ Biped walks slowly, so enough time to avoid
obstacles
Integrated Peripherals - ADC
Accumulate timer tickets to trigger the following actions:◦ Set and reset PWM duty register◦ Read output from ultrasonic range finder◦ Send status message to PC
Integrated Peripherals – Timer
User-Control Mode◦ Read control message, act accordingly◦ Assume no need to self-balance or avoid obstacle
– user should take care of it
Auto-Navigation Mode◦ Read environment data, walk freely while
avoiding obstacles and balancing itself
Two Modes of Operation
State Machine + Interrupt Driven + Pooling Loop
Two States:◦ User-control state◦ Auto-navigation state
Interrupts: WiFly, accelerometer, timer
Interrupts service routines set flags, infinite main loop checks flags and acts accordingly
Organization of Code
Four Main Actions: Walk, Turn, Stop, Balance
Each action done by doing sub-actions◦ Walk: lift left foot -> bent for balancing -> move left
foot to front -> …
Static sub-actions and Dynamic sub-actions
Variables to store foot positions and states
Periodically adjust itself
How Biped Acts?
Static sub-action: pre-defined array of foot positions and orientations (stored in flash)
Static sub-actions performed under default conditions (no significant external force other than gravity)
When a static sub-action is done, modify foot position and foot position state
If needs to change to another action, move to another sub-action based on current foot position state
How Biped Acts? (cont) Static Sub-Action
Dynamic sub-action: calculate next foot position and orientation based on current foot position and environment information (acceleration, …)
Significant external force -> Switch from static sub-action to dynamic sub-action
When possible -> switch back to static sub-action
How to calculate next foot position? – not yet know
How Biped Acts? (cont) Dynamic Sub-Action
Interrupt Service - SPIo Balance itself under significant
external force (dynamic sub-actions).
o In SPI ISR, SPI interrupt is also handled but simply change acceleration value.
o Return with each servos at their positions before interrupt – to resume appropriate static sub-action
Read message from WiFly card and push it to message queue – possibly pending messages
Increment msgCnt by 1
Note: SCI interrupt is disabled/ignored when serving SPI interrupt
Interrupt Service - SCI
PWM-Servo Control module◦ Control the servo to turn to given an angle
Inverse-Kinematics module◦ Given a foot position and orientation, calculate
servo angles
Next-Sub-Action module◦ Based on the action to perform and current feet
positions, determine next sub-action to perform
Code Modules
Dynamic-Next-Position module◦ Based on environment information and current foot
positions, find next foot positions to balance itself
SCI-WiFly module◦ Provides functions initializing SCI port 1, sending
messages to and receiving messages from WiFly card
MsgParser module◦ Parse messages received from WiFly card and set
appropriate global variables.
Code Modules (cont)
SPI-Accelerometer moduleSPI initialization; SPI interrupt service routine
ADC–Obstacle module◦ ATD channel initialization; Read and set obstacle
distance and modify other variables if needed
Timer module◦ Timer initialization; Timer interrupt service routine
Status LED module
Code Modules (cont)