Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
doc:beginner:simple_plans [2013/12/12 14:46] – gkazhoya | doc:beginner:simple_plans [2015/05/11 16:59] (current) – removed gkazhoya | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Implementing simple plans to move a turtle ====== | ||
- | **Description: | ||
- | |||
- | |||
- | **Next Tutorial: | ||
- | |||
- | |||
- | ===== Moving the turtle towards a point ===== | ||
- | |||
- | |||
- | To move from one waypoint to the next one, we need to calculate the angular and linear velocity commands. We do that by transforming the goal pose into the turtle' | ||
- | |||
- | < | ||
- | (defun pose-msg-> | ||
- | " | ||
- | (with-fields (x y theta) msg | ||
- | (cl-transforms: | ||
- | | ||
- | | ||
- | (cl-transforms: | ||
- | theta)))) | ||
- | |||
- | (defun relative-angle-to (goal pose) | ||
- | "Given a pose as 3d-pose msg and a goal as 3d vector, | ||
- | calculate the angle by which the pose has to be turned to point toward the goal." | ||
- | (let ((diff-pose (cl-transforms: | ||
- | | ||
- | | ||
- | | ||
- | (atan | ||
- | (cl-transforms: | ||
- | (cl-transforms: | ||
- | |||
- | (defun calculate-angular-cmd (goal & | ||
- | "Uses the current turtle pose and calculates the angular velocity | ||
- | command to turn towards the goal." | ||
- | (* ang-vel-factor | ||
- | | ||
- | </ | ||
- | |||
- | |||
- | The function '' | ||
- | |||
- | As an example, assume the turtle is at '' | ||
- | |||
- | In order to move the turtle towards a point, we need to continuously recalculate and send the velocity command at a specific rate. The rate must be sufficiently high, since the sent command needs to change while the turtle moves. Let's see if our code does what it should do. Enter in the Lisp REPL: | ||
- | |||
- | < | ||
- | TUT> (dotimes (i 100) | ||
- | | ||
- | 1.5 ; linear speed | ||
- | | ||
- | | ||
- | </ | ||
- | |||
- | (Note: you need to reload your asdf system each time you want to try in Repl some Lisp code that you updated just now.) | ||
- | |||
- | The code calls '' | ||
- | |||
- | The turtle should now move towards the bottom left corner and finally move along a circle around the goal until the loop finishes. | ||
- | |||
- | ===== Writing a plan to move to a waypoint ===== | ||
- | |||
- | |||
- | Now we need to write a simple plan that recalculates and executes the velocity command until we reach the goal. The easiest way to do that is to construct a fluent over the distance to the goal and use pursue to monitor it in parallel to the control loop. Here the code: | ||
- | |||
- | < | ||
- | (def-cram-function move-to (goal & | ||
- | (let ((reached-fl (< (fl-funcall #' | ||
- | | ||
- | #' | ||
- | (fl-funcall | ||
- | #' | ||
- | | ||
- | goal) | ||
- | | ||
- | (unwind-protect | ||
- | | ||
- | | ||
- | (loop do | ||
- | | ||
- | 1.5 | ||
- | | ||
- | | ||
- | (send-vel-cmd 0 0)))) | ||
- | </ | ||
- | | ||
- | When we want to use CRAM language features such as '' | ||
- | |||
- | The fluent network that we construct looks pretty complicated. We first transform the pose message into a '' | ||
- | |||
- | The '' | ||
- | |||
- | The '' | ||
- | |||
- | To execute CRAM Language code we need to either call it from a function that was defined with '' | ||
- | < | ||
- | TUT> (top-level | ||
- | | ||
- | | ||
- | </ | ||
- | |||
- | The turtle should now move along a rectangle. |