Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "Experiment.hpp"
00009
00010 #include <telekyb_base/ROS.hpp>
00011 #include <telekyb_base/Time.hpp>
00012
00013 #include <telekyb_base/Spaces.hpp>
00014
00015
00016 ExperimentOptions::ExperimentOptions()
00017 : OptionContainer("ExperimentOptions")
00018 {
00019 robotID = addOption<int>("robotID", "Specify the robotID of the TeleKybCore to connect to.", 0, false, true);
00020 tJoystickTopic = addOption<std::string>("tJoystickTopic",
00021 "Joysticktopic to use (sensor_msgs::Joy)", "/TeleKyb/tJoy/joy", false, true);
00022 tUseMKInterface = addOption<bool>("tUseMKInterface", "Set to true with MKInterface!", false, false, true);
00023
00024 tTrajectoryFileName = addOption<std::string>("tTrajectoryFileName",
00025 "Full path of the trajectory file", "", true, true);
00026
00027 tTrajectoryStartPoint = addOption<Eigen::Vector3d>("tTrajectoryStartPoint",
00028 "Starting position of the trajectory", Eigen::Vector3d(0.0,0.0,-1.0), true, true);
00029 }
00030
00031 Experiment::Experiment()
00032 : mainNodeHandle( ROSModule::Instance().getMainNodeHandle() ), core(NULL), mkInterface(NULL)
00033 {
00034 core = telekyb_interface::TeleKybCore::getTeleKybCore(options.robotID->getValue());
00035 if (!core) {
00036
00037 ros::shutdown();
00038 return;
00039 }
00040
00041
00042 if (options.tUseMKInterface->getValue()) {
00043 ROS_INFO("Creating MKInterface!");
00044
00045 mkInterface = telekyb_interface::MKInterface::getMKInterface(options.robotID->getValue());
00046
00047 if (!mkInterface) {
00048
00049 ros::shutdown();
00050 return;
00051 }
00052 }
00053
00054 bController = core->getBehaviorController();
00055 oController = core->getOptionController();
00056
00057
00058 bController->setActiveBehaviorListener(this);
00059
00060 activeBehaviorPtr = bController->getActiveBehaviorPointer();
00061
00062 setupExperiment();
00063 }
00064
00065 Experiment::~Experiment()
00066 {
00067 if (mkInterface) { delete mkInterface; }
00068
00069 delete core;
00070 }
00071
00072 void Experiment::setupExperiment()
00073 {
00074
00075 ground = bController->getSystemBehavior("tk_behavior/Ground");
00076 hover = bController->getSystemBehavior("tk_behavior/Hover");
00077 normalBreak = bController->getSystemBehavior("tk_behavior/NormalBrake");
00078 takeOff = bController->getSystemBehavior("tk_behavior/TakeOff");
00079 land = bController->getSystemBehavior("tk_behavior/Land");
00080
00081
00082
00083 if (ground.isNull() || hover.isNull() || normalBreak.isNull() || takeOff.isNull() || land.isNull()) {
00084 ROS_FATAL("Unable to get SystemBehavior!!!");
00085
00086 ros::shutdown();
00087 }
00088
00089
00090
00091 takeOff.getOptionContainer().getOption("tTakeOffVelocity").set<double>(0.3);
00092 takeOff.getOptionContainer().getOption("tTakeOffDestination").set(Position3D(0.0,0.0,-1.0));
00093 takeOff.getOptionContainer().getOption("tTakeOffVertically").set(true);
00094
00095
00096 takeOff.setParameterInitialized(true);
00097
00098
00099 land.getOptionContainer().getOption("tLandVelocity").set<double>(0.4);
00100 land.getOptionContainer().getOption("tLandDestination").set(Position3D(0.0,0.0,0.0));
00101 land.getOptionContainer().getOption("tLandDestinationHeight").set<double>(-0.3);
00102 land.getOptionContainer().getOption("tLandVertically").set(true);
00103
00104
00105
00106 land.setParameterInitialized(true);
00107
00108
00109
00110 trajPlayback = bController->loadBehavior("tk_be_common/TrajPlayback");
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 if ( trajPlayback.isNull() ) {
00123 ROS_FATAL("Unable to load Trajectory Playback!!!");
00124
00125 ros::shutdown();
00126 }
00127
00128 trajPlayback.getOptionContainer().getOption("tTrajectoryFilename").set(options.tTrajectoryFileName->getValue());
00129 trajPlayback.setParameterInitialized(true);
00130
00131 flyto1 = bController->loadBehavior("tk_be_common/LinearFlyTo");
00132
00133
00134
00135 flyto1.getOptionContainer().getOption("tFlyToDestination").set(options.tTrajectoryStartPoint->getValue());
00136
00137
00138
00139 flyto1.setParameterInitialized(true);
00140
00141
00142
00143
00144
00145
00146
00147 if (*activeBehaviorPtr != ground) {
00148 ROS_ERROR("UAV not in Ground Behavior during Startup");
00149 ros::shutdown();
00150 }
00151
00152
00153 joySub = mainNodeHandle.subscribe(options.tJoystickTopic->getValue()
00154 , 10, &Experiment::joystickCB, this);
00155 }
00156
00157
00158
00159
00160 void Experiment::joystickCB(const sensor_msgs::Joy::ConstPtr& msg)
00161 {
00162
00163 if (msg->buttons.size() < 9) {
00164 ROS_ERROR("Jostick does not publish enough buttons.");
00165 return;
00166 }
00167
00168
00169 if (msg->buttons[6]) {
00170 ROS_WARN("Emergency Button pressed!");
00171
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 if (msg->buttons[2]) {
00201 if (*activeBehaviorPtr == ground) {
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 bController->switchBehavior(takeOff);
00219 } else {
00220
00221 bController->switchBehavior(land);
00222 }
00223 }
00224
00225
00226
00227
00228
00229 if (msg->buttons[4]) {
00230 bController->switchBehavior(trajPlayback);
00231 }
00232
00233
00234 if (msg->buttons[3]) {
00235 bController->switchBehavior(flyto1);
00236 }
00237
00238
00239 }
00240
00241 void Experiment::activeBehaviorChanged(telekyb_interface::Behavior newActiveBehavior)
00242 {
00243
00244
00245
00246
00247
00248
00249
00250 if(newActiveBehavior == normalBreak) {
00251 ROS_INFO("Going to normalbrake");
00252 }
00253
00254 }
00255