This is an old revision of the document!


Using Cram in Unreal Engine

Description: In this tutorial you will learn..

Previous Tutorial: Controlling turtlesim from CRAM
Next Tutorial: Using Prolog for reasoning

To run the code in the tutuorial the roscore and the turtlesim need to be started over the terminal. Each in their own tab.

$ roscore
$ rosrun turtlesim turtlesim_node

Moving ...

Go to the src directory of your tutorial and create a new file, simple-plans.lisp. Open it and add the following code:

(in-package :tut)
 
(defun pose-msg->transform (msg)
  "Returns a transform proxy that allows to transform into the frame
given by x, y, and theta of `msg'."
  (with-fields (x y theta) msg
    (cl-transforms:make-transform
     (cl-transforms:make-3d-vector x y 0)
     (cl-transforms:axis-angle->quaternion
      (cl-transforms:make-3d-vector 0 0 1)
      theta))))
 
(defun relative-angle-to (goal pose-msg)
  "Given a `pose-msg' as a turtlesim-msg:pose and a `goal' as cl-transforms:3d-vector,
calculate the angle by which the pose has to be turned to point toward the goal."
  (let ((diff-pose (cl-transforms:transform-point
                     (cl-transforms:transform-inv
                       (pose-msg->transform pose-msg))
                     goal)))
    (atan
      (cl-transforms:y diff-pose)
      (cl-transforms:x diff-pose))))
 
(defun calculate-angular-cmd (goal &optional (ang-vel-factor 8))
  "Uses the current turtle pose and calculates the angular velocity command
to turn towards the goal."
  (* ang-vel-factor
     (relative-angle-to goal (value *turtle-pose*))))

You will also need to update your *.asd file by adding a dependency to the newly created simple-plans.lisp by adding this line to the :components field of the src module: