Project

General

Profile

Revision 737bd480

ID737bd480c2804eafbf35b37013d72c980d757d40

Added by Thomas Mullins about 12 years ago

Added altitude_node and node_control

node_control listens to /mikrokopter/thrust, yaw, and velocity, and
publishes control messages using nav_lib. altitude_node publishes to
/mikrokopter/thrust using PID_control on barometer values.

View differences:

mikrokopter/CMakeLists.txt
21 21
#uncomment if you have defined services
22 22
#rosbuild_gensrv()
23 23

  
24
#common commands for building c++ executables and libraries
25 24
rosbuild_add_executable(${PROJECT_NAME} src/mikrokopter_node.cpp src/interface.cpp)
26 25
target_link_libraries(${PROJECT_NAME} serial)
27 26

  
......
29 28
rosbuild_add_executable(keyboard_control src/keyboard_control.cpp src/nav_lib.cpp)
30 29
target_link_libraries(keyboard_control ncurses)
31 30
rosbuild_add_executable(joystick_control src/joystick_control.cpp src/nav_lib.cpp)
31
rosbuild_add_executable(node_control src/node_control.cpp src/nav_lib.cpp)
32 32
rosbuild_add_executable(CoordToPID src/CoordToPID.cpp src/nav_lib.cpp ../control/pid_control.cpp)
33 33
rosbuild_add_executable(mk_wrapper src/mk_wrapper.cpp)
mikrokopter/altitude_node/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
rosbuild_init()
5

  
6
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
7
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
8

  
9
#rosbuild_genmsg()
10
#rosbuild_gensrv()
11

  
12
rosbuild_add_executable(${PROJECT_NAME} src/altitude_node.cpp ../../control/pid_control.cpp)
mikrokopter/altitude_node/Makefile
1
include $(shell rospack find mk)/cmake.mk
mikrokopter/altitude_node/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b altitude_node is ... 
6

  
7
<!-- 
8
Provide an overview of your package.
9
-->
10

  
11

  
12
\section codeapi Code API
13

  
14
<!--
15
Provide links to specific auto-generated API documentation within your
16
package that is of particular interest to a reader. Doxygen will
17
document pretty much every part of your code, so do your best here to
18
point the reader to the actual API.
19

  
20
If your codebase is fairly large or has different sets of APIs, you
21
should use the doxygen 'group' tag to keep these APIs together. For
22
example, the roscpp documentation has 'libros' group.
23
-->
24

  
25

  
26
*/
mikrokopter/altitude_node/manifest.xml
1
<package>
2

  
3
  <description brief="altitude_node">
4
    Publishes thrust settings to /mikrokopter/thrust based on height information
5
  </description>
6
  <author>Tom Mullins</author>
7
  
8
  <depend package="roscpp"/>
9
  <depend package="std_msgs"/>
10
  <depend package="mikrokopter"/>
11

  
12
</package>
13

  
14

  
mikrokopter/altitude_node/src/altitude_node.cpp
1
#include "ros/ros.h"
2
#include "std_msgs/Float64.h"
3
#include "mikrokopter/FcDebug.h"
4
#include "../../../control/pid_control.h"
5

  
6
class AltitudeNode
7
{
8
public:
9
  AltitudeNode();
10
  void main_loop() {ros::spin();}
11
  void height_cb(const mikrokopter::FcDebug::ConstPtr& fc);
12
  void goal_cb(const std_msgs::Float64::ConstPtr& goal);
13

  
14
private:
15
  PID_control pid;
16
  ros::NodeHandle n;
17
  ros::Publisher pub;
18
  ros::Subscriber height_sub;
19
  ros::Subscriber goal_sub;
20
};
21

  
22
AltitudeNode::AltitudeNode() : pid(10, 0, 0, 0)
23
{
24
  height_sub = n.subscribe<mikrokopter::FcDebug>("/mikrokopter/fc_debug",
25
      100, &AltitudeNode::height_cb, this);
26
  goal_sub = n.subscribe<std_msgs::Float64>("/mikrokopter/height_goal",
27
      100, &AltitudeNode::goal_cb, this);
28
  pub = n.advertise<std_msgs::Float64>("/mikrokopter/thrust", 100);
29
}
30

  
31
void AltitudeNode::height_cb(const mikrokopter::FcDebug::ConstPtr& fc)
32
{
33
  std_msgs::Float64 msg;
34
  msg.data = pid.pid(fc->heightValue, fc->header.stamp.toNSec());
35
  pub.publish(msg);
36
}
37

  
38
void AltitudeNode::goal_cb(const std_msgs::Float64::ConstPtr& goal)
39
{
40
  pid.change_goal(goal->data);
41
}
42

  
43
int main(int argc, char **argv) {
44
  ros::init(argc, argv, "altitude_node");
45
  AltitudeNode an = AltitudeNode();
46
  an.main_loop();
47
  return 0;
48
}
mikrokopter/src/nav_lib.cpp
58 58

  
59 59
void MikrokopterControl::set_thrust(float thrust)
60 60
{
61
    if (thrust < 0) thrust = 0;
62
    if (thrust > 1) thrust = 1;
61 63
    int k = 255;
62 64
    control.thrust = k*thrust;
63 65
}

Also available in: Unified diff