Skip to content

This repo implements a C++ based class to control the motion of thrustered vehicles such as Drones, AUVs,etc

License

Notifications You must be signed in to change notification settings

auvsociety/thrustered_vehicle_motioncontroller

Repository files navigation

thrustered_vehicle_motioncontroller

This repo implements a C++ based class to control the motion of thrustered vehicles such as Drones, AUVs,etc. The repo can also be used with python using pybind11.

Why This Project?

Be it drones, ROVs, AUVs or UAVs, Even though they are mechanically different and serve different purposes. There's one thing that remains constant. To control the vehicle you have to control the speed of the motors. The speed ratio, no of motors and combination required to achieve a particular motion varies from vehicle to vehicle. So, instead of writing the motion control code for every vehicle each and every time, I wanted to make an abstracted object where you can edit all the above parameters by simply editing the macros for each vehicle.

Output Method:

The current version of code, gets command and publishes the PWM values in a topic called /pwm_values in ros. The pwm values range from from 1100 to 1900 meant for BlueRobotics Blue ESC. Depending on your application you can modify the thrusters_controller.cpp file to suit your output method.

Terms and Notations Used:

Certain terms have been used in this code for ease of usage. As i strongly believe that No matter How obvious the terms are, If not defined before usage, They do more harm than good. We will define certain terms used to denote different kind of Motion: motion_surge_sway_heave Image courtesy: Formula one directory

Surge:

Linear Motion along X axis.

surging-motion-example-surge-movement-on-cargo-ship-at-sea GIF courtesy: FFQO.com

Sway:

Linear motion along Y axis.

Heave:

Linear motion along Z axis.

Yaw:

Rotational motion about Z axis

pitch:

Rotational motion about Y axis

Roll:

Rotational motion about X axis

Installation :

Cloning this repository:

       Clone this repo using the following command as it contains submodules:
    git clone --recurse-submodules https://github.com/auvsocietyiiitdm/thrustered_vehicle_motioncontroller.git

C++ (ROS) :

      Currently i am not providing any compiled library, So the user has to compile it on his own. Create your own ROS package. Clone this repo on your package/src folder. Create a CMakeLists.txt file in your_package/src and add src as subdirectory in topmost CMakeLists.txt of your ROS Package. add this as subdirectory in your_package/src/CMakeLists.txt . Include the header file and use the API in your code. And finally, In your CMakeLists.txt file, while building your ros node, add this line. For example, you are using this library inside a node called "ros_node". use this repo as a reference:https://github.com/auvsocietyiiitdm/motion_example.git
      to learn about ros: http://wiki.ros.org/ROS/Introduction
      for more info on creating ros packages: http://wiki.ros.org/ROS/Tutorials/CreatingPackage
      target_link_libraries( ros_node <TARGET_OBJECTS:thrustered_vehicle_motioncontroller>)

Python (ROS):

        Just add this to your ros package src folder and add this as subdirectory in the CMakeLists.txt file inside the src folder. Python Module will be automatically compiled and will be placed in your catkin_ws/devel/lib folder. import and use the module like any other python code.

Custom Output :

         Just define your own output function and add this repo as subdirectory  in your own CMake File and  add this line:
      target_link_libraries( ros_node OBJECT thrustered_vehicle_motioncontroller)

API Usage:

* This code does not differentiate between any degree of freedom. So, it makes sense to define api usage for a single degree of freedom let's say Surge. this applies equall to remaining 5 Degrees. This library allows the bot to be controlled either using Open loop mode or PID (closed loop mode). The mode should be set manually before using controls on that degree of freedom. Also the updateThrustValues should be called everytime you change any of the thrust values. This can be automatically done, But I have designed it purposely so that the user can change multiple degrees of freedom simultaneously.

setSurgeControlMode( bool control_mode ):

          Changes the control mode, 1 means open loop and 0 means Closed Loop.

setSurgeThrust( int thrust):

           Changes the thrust value, limits thrust to defined MIN,Max values in config file. Works only in Open Loop Mode.

setTargetSurgePoint(float point):

           Sets the target point for closed loop control.

setCurrentSurgePoint(float point):

           Sets the current point for closed loop control and update the pid values and sets thrust.

updateThrustValues()

          Updates the Previously set thrust Values

resetAllThrsuters()

         Sets  All thruster value to zero.

refresh:

          Should be called often so that thruster values get updated in ROS.

Note: While calling the above functions for rotational degree of freedoms like roll, pitch, yaw 'Angle' should be used instead of 'Point'.

Configuring for custom Vehicles:

         All the custom values such as default control  mode, thruster combination, no of thrusers for each of the six degree of freedom should be modified in the vehice_config.h file. Also Number of thrusters, Max pwm and min pwm should be modified in the thrusters_controller.h file. Then compile the code again.

About

This repo implements a C++ based class to control the motion of thrustered vehicles such as Drones, AUVs,etc

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published