Mercurial > uBob
changeset 3:e86979b47473
Walking forward
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 16 Jan 2015 16:20:10 +0100 |
| parents | b3dfeb2fe248 |
| children | c0e23288f36b |
| files | ubob.lua |
| diffstat | 1 files changed, 45 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/ubob.lua Fri Jan 16 15:01:22 2015 +0100 +++ b/ubob.lua Fri Jan 16 16:20:10 2015 +0100 @@ -1,60 +1,70 @@ -SWAY_TRIM = 96; -LEFT_TRIM = 88; -RIGHT_TRIM = 94; +POSES = {{0, 10, 10}, {15, 10, 10}, {15, -10, -10}, {0, -10, -10}, {-15, -10, -10}, {-15, 10, 10}} -sway_pos = 0; -left_pos = 0; -right_pos = 0; -moving = false; +sway_pos = 0 +left_pos = 0 +right_pos = 0 +pose_step = 1 -sway = 0; -left = 0; -right = 0; +sway = 0 +left = 0 +right = 0 function start() - pwm.setup(5, 60, 94); - pwm.setup(6, 60, 88); - pwm.setup(7, 60, 96); - pwm.start(5); - pwm.start(6); - pwm.start(7); + pwm.setup(5, 60, 94) + pwm.setup(6, 60, 88) + pwm.setup(7, 60, 96) + pwm.start(5) + pwm.start(6) + pwm.start(7) - tmr.alarm(5, 25, 1, update); -end; + tmr.alarm(5, 25, 1, update) +end + function next_pose() + local pose = 0 + pose_step = pose_step + 1 + pose = POSES[pose_step] + if pose == nil then + pose_step = 1 + pose = POSES[pose_step] + end + sway = pose[1] + left = pose[2] + right = pose[3] end + function update() - moving = false; + local moving = false if sway > sway_pos then - sway_pos = sway_pos + 1; - moving = true; + sway_pos = sway_pos + 1 + moving = true elseif sway < sway_pos then - sway_pos = sway_pos - 1; - moving = true; + sway_pos = sway_pos - 1 + moving = true end if left > left_pos then - left_pos = left_pos + 1; - moving = true; + left_pos = left_pos + 1 + moving = true elseif left < left_pos then - left_pos = left_pos - 1; - moving = true; + left_pos = left_pos - 1 + moving = true end if right > right_pos then - right_pos = right_pos + 1; - moving = true; + right_pos = right_pos + 1 + moving = true elseif right < right_pos then - right_pos = right_pos - 1; - moving = true; + right_pos = right_pos - 1 + moving = true end if moving == false then - next_pose(); + next_pose() end - pwm.setduty(7, SWAY_TRIM + sway_pos); - pwm.setduty(6, LEFT_TRIM + left_pos); - pwm.setduty(5, RIGHT_TRIM + right_pos); + pwm.setduty(7, 96 + sway_pos) + pwm.setduty(6, 88 + left_pos) + pwm.setduty(5, 94 + right_pos) end
