Wiki

Clone wiki

scl-manips-group / docu / own_controllers

Writing your own controllers

  • Look at the applications-linux directory and copy paste the example controller

Copy paste the example application:

$ cd your-base-git-dir.git
$ cd applications-linux/
$ cp -rf scl_example_ctrl scl_samir_ctrl
$ rm -rf scl_samir_ctrl/build_*

Just remember, it is good coding practice to use version control while you do this.

$ cd scl_samir_ctrl/
$ git branch samir_ctrl_dev
$ git checkout samir_ctrl_dev
$ git add *pp
$ git add *sh
$ git add CMakeLists.txt
$ git commit . -m "Adding samir's cool new controller"
$ gitk (this should show you your new controller)

Now we change the Example stuff to your task's name

$ for foo in `find . -name '*'`;
do
cat $foo | sed 's/Example/SamirDidThis/g' > foo2;
echo Updating $foo;
mv foo2 $foo;
done
$ for foo in `find . -name '*'`;
do
cat $foo | sed 's/EXAMPLE/SAMIRDIDTHIS/g' > foo2;
echo Updating $foo;
mv foo2 $foo;
done
$ for foo in `find . -name '*txt'`;
do
cat $foo | sed 's/example/samir/g' > foo2;
echo Updating $foo;
mv foo2 $foo;
done
$ for foo in `find . -name '*txt'`;
do
cat $foo | sed 's/eg/samir/g' > foo2;
echo Updating $foo;
mv foo2 $foo;
done
$ for foo in `find . -name '*sh'`;
do
cat $foo | sed 's/example/samir/g' > foo2;
echo Updating $foo;
mv foo2 $foo;
done
$ for foo in `find . -name '*sh'`;
do
cat $foo | sed 's/eg/samir/g' > foo2;
echo Updating $foo;
mv foo2 $foo;
done

* And voila. All the *pp files converted Example to SamirDidThis. Check with:

$ git diff .

* I trust you made a sensible decision with your naming scheme. If not, there's git (you can thank me now for forcing you to set up your branch):

$ git reset HEAD --hard

Now commit your changes:

$ git commit . -m "Changed the controller name from Example to my own controller"

* Hopefully this teaches you to use version control regularly. Please do so. It will save your life later. But your code won't compile yet. You still have to change file names:

$ for foo in `find . -name '*pp'`;
do
echo $foo | sed s/Example/SamirDidThis/g > foo2;
echo git mv $foo `cat foo2`;
git mv $foo `cat foo2`;
done
$ git mv scl_example_main.cpp scl_samir_main.cpp

Now commit your changes:

$ git commit . -m "Changed the renamed files from Example to my own controller"

Finally, compile and run your new controller.

$ sh make_dbg.sh
$ sh make_rel.sh
$ chmod +x scl_samir_ctrl

* And you are good to go.

Programming the new Control Task

  • When you copy your controller, and have renamed everything related to the task from "*Example*" to "*SamirDidThis*" (or whatever name you choose), you still have to fill in the controller.
  • Copy the controller as mentioned above. Open a terminal, type:
$ grep TODO *pp
  • This will display what you have to do to get your controller running, and will look something like this:
CSamirDidThisTask.cpp:      //TODO : COMPUTE SERVO GENERALIZED FORCES
CSamirDidThisTask.cpp:      //TODO : COMPUTE DYNAMIC MODEL (if not a generalized coordinate task)
CSamirDidThisTask.cpp:      //TODO : COMPUTE NULL SPACE
CSamirDidThisTask.hpp:     * CTaskBase API : TODO : IMPLEMENT THESE!!
CSamirDidThisTask.hpp:    //TODO : Add what you want.

Do that stuff (read Oussama's book, learn the equations, model your controller, and plug in the equations into the TODO).

Adding a new Control Task

  1. Now lets say you want to add another task. Repeat the above steps but instead of 'mv', use 'cp' in the shell scripts, and you will get a copy of the files required to run a new task.
  2. The next step is to find out what you need to change in the code, run:
grep SamirDidThis *pp

The output of the grep related to the app files, will also tell you what you need to change to implement another task.

Updated