Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <icl_hardware_canopen/CanOpenController.h>
00014 #include <icl_hardware_canopen/DS301Group.h>
00015 #include <icl_hardware_canopen/SchunkPowerBallNode.h>
00016 #include <icl_hardware_canopen/DS402Group.h>
00017 #include <icl_hardware_canopen/exceptions.h>
00018 #include <icl_hardware_canopen/PDO.h>
00019
00020 #include <icl_hardware_canopen/Logging.h>
00021 #include "../ds402.h"
00022
00023 #include <cstdlib>
00024 #include <boost/filesystem.hpp>
00025
00026 using namespace icl_hardware::canopen_schunk;
00027
00028 int main (int argc, char* argv[])
00029 {
00030
00031 icl_core::logging::initialize(argc, argv);
00032
00033 CanOpenController my_controller("auto");
00034
00035 my_controller.addGroup<DS402Group>("arm");
00036 my_controller.addNode<SchunkPowerBallNode>(3, "arm");
00037 my_controller.addNode<SchunkPowerBallNode>(4, "arm");
00038 my_controller.addNode<SchunkPowerBallNode>(5, "arm");
00039 my_controller.addNode<SchunkPowerBallNode>(6, "arm");
00040 my_controller.addNode<SchunkPowerBallNode>(7, "arm");
00041 my_controller.addNode<SchunkPowerBallNode>(8, "arm");
00042
00043 std::vector <uint8_t> output_data;
00044 sleep(5);
00045
00046 boost::filesystem::path resources_path;
00047 char const* tmp = std::getenv("CANOPEN_RESOURCE_PATH");
00048 if (tmp == NULL)
00049 {
00050 LOGGING_WARNING_C(
00051 CanOpen,
00052 CanOpenController,
00053 "The environment variable 'CANOPEN_RESOURCE_PATH' could not be read. Using relative path 'resources/'" << endl);
00054 resources_path = boost::filesystem::path("resources");
00055 }
00056 else
00057 {
00058 resources_path = boost::filesystem::path(tmp);
00059 }
00060
00061 std::string emcy_emergency_errors_filename = (resources_path / boost::filesystem::path("EMCY_schunk.ini")).string();
00062 EMCY::addEmergencyErrorMap( emcy_emergency_errors_filename, "schunk_error_codes");
00063
00064
00065
00066 SchunkPowerBallNode::Ptr node_3 = my_controller.getNode<SchunkPowerBallNode> (3);
00067 SchunkPowerBallNode::Ptr node_4 = my_controller.getNode<SchunkPowerBallNode> (4);
00068 SchunkPowerBallNode::Ptr node_5 = my_controller.getNode<SchunkPowerBallNode> (5);
00069 SchunkPowerBallNode::Ptr node_6 = my_controller.getNode<SchunkPowerBallNode> (6);
00070 SchunkPowerBallNode::Ptr node_7 = my_controller.getNode<SchunkPowerBallNode> (7);
00071 SchunkPowerBallNode::Ptr node_8 = my_controller.getNode<SchunkPowerBallNode> (8);
00072
00073
00074 DS402Group::Ptr arm_group = my_controller.getGroup<DS402Group>("arm");
00075
00076 SchunkPowerBallNode::Ptr node = node_7;
00077
00078 if (node)
00079 {
00080 node->m_nmt.preOperational();
00081 node->printPDOMapping();
00082
00083
00084
00085
00086
00087
00088 node->initNode();
00089 node_8->initNode();
00090 node->printSupportedModesOfOperation();
00091
00092 node->setModeOfOperation(ds402::MOO_PROFILE_POSITION_MODE);
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 }
00121 else
00122 {
00123 arm_group->initNodes();
00124 }
00125
00126
00127
00128 std::cout << std::endl << std::endl << std::endl << std::endl << std::endl << std::endl;
00129
00130 LOGGING_DEBUG (CanOpen, "Running syncAll once" << endl);
00131 my_controller.syncAll();
00132
00133
00134
00135
00136
00137
00138 try
00139 {
00140 if (node)
00141 {
00142
00143
00144 }
00145 else
00146 {
00147 node_8->commutationSearch();
00148 std::cout << std::endl << std::endl << std::endl << std::endl << std::endl;
00149 sleep(2);
00150 node_7->commutationSearch();
00151 sleep(2);
00152 node_6->commutationSearch();
00153 sleep(2);
00154 node_5->commutationSearch();
00155 sleep(2);
00156 node_4->commutationSearch();
00157 sleep(2);
00158 node_3->commutationSearch();
00159
00160
00161 }
00162 }
00163 catch (const std::exception& e)
00164 {
00165 LOGGING_ERROR (CanOpen, e.what() << endl);
00166 return -1;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 std::cout << std::endl << std::endl << std::endl << std::endl << std::endl << std::endl;
00176
00177
00178
00179 size_t counter = 0;
00180 double target_position = 0.05;
00181 double current_position = 0;
00182
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00212
00213
00214 node_8->enableNode(ds402::MOO_PROFILE_POSITION_MODE);
00215 while (counter < 5000)
00216 {
00217 try {
00218 my_controller.syncAll();
00219 }
00220 catch (const std::exception& e)
00221 {
00222 LOGGING_ERROR (CanOpen, e.what() << endl);
00223 return -1;
00224 }
00225
00226 usleep(10000);
00227
00228 if (counter > 2)
00229 {
00230 if (node)
00231 {
00232 node->printStatus();
00233 }
00234 else
00235 {
00236 arm_group->printStatus();
00237 }
00238 }
00239
00240 if (counter == 5)
00241 {
00242 try
00243 {
00244 node->enableNode(ds402::MOO_INTERPOLATED_POSITION_MODE);
00245 current_position = static_cast<double>(node->getTPDOValue<int32_t>("measured_position")) / SchunkPowerBallNode::RAD_TO_STEPS_FACTOR;
00246 LOGGING_INFO (CanOpen, "Current position: " << current_position << endl);
00247 }
00248 catch (const std::exception& e)
00249 {
00250 LOGGING_ERROR (CanOpen, e.what() << endl);
00251 return -1;
00252 }
00253 }
00254
00255 if (counter == 50 )
00256 {
00257 node_8->setTarget(1.57);
00258 }
00259
00260 if (counter == 500 )
00261 {
00262 node_8->setTarget(-1.57);
00263 }
00264
00265 if (counter == 1000 )
00266 {
00267 node_8->setTarget(1.57);
00268 }
00269 if (counter == 2000 )
00270 {
00271 node_8->setTarget(-1.57);
00272 }
00273
00274 if (counter > 5 && counter < 299)
00275 {
00276 double starting_point = asin(current_position);
00277 target_position = sin(0.01*(counter-6) + starting_point);
00278 LOGGING_INFO (CanOpen, "Sinus target: " << target_position << endl);
00279
00280 node->setTarget(target_position);
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 if (counter == 300)
00313 {
00314 node->quickStop();
00315 LOGGING_INFO (CanOpen, "QuickStopped" << endl);
00316 }
00317
00318 if (counter == 600)
00319 {
00320 current_position = static_cast<double>(node->getTPDOValue<int32_t>("measured_position")) / SchunkPowerBallNode::RAD_TO_STEPS_FACTOR;
00321 LOGGING_INFO (CanOpen, "Current position: " << current_position << endl);
00322 node->enableNode(ds402::MOO_INTERPOLATED_POSITION_MODE);
00323 }
00324
00325 if (counter >= 605 && counter < 800 )
00326 {
00327 double starting_point = asin(current_position);
00328 target_position = sin(0.01*(counter-605) + starting_point);
00329 LOGGING_INFO (CanOpen, "Sinus target: " << target_position << endl);
00330 node->setTarget(target_position);
00331
00332 }
00333
00334 if (counter == 600)
00335 {
00336 try
00337 {
00338
00339
00340
00341
00342
00343
00344 }
00345 catch (const std::exception& e)
00346 {
00347 LOGGING_ERROR (CanOpen, e.what() << endl);
00348 return -1;
00349 }
00350
00351 }
00352
00353 if (counter == 880)
00354 {
00355 node->closeBrakes();
00356 }
00357
00358
00359 if (counter == 1000)
00360 {
00361 current_position = static_cast<double>(node->getTPDOValue<int32_t>("measured_position")) / SchunkPowerBallNode::RAD_TO_STEPS_FACTOR;
00362 LOGGING_INFO (CanOpen, "Current position: " << current_position << endl);
00363 node->openBrakes();
00364 }
00365
00366 if (counter >= 1005 && counter < 2000)
00367 {
00368 LOGGING_INFO (CanOpen, "Current position: " << current_position << endl);
00369 double starting_point = asin(current_position);
00370 target_position = sin(0.01*(counter-1005) + starting_point);
00371 LOGGING_INFO (CanOpen, "Sinus target: " << target_position << endl);
00372 node->setTarget(target_position);
00373 }
00374
00375 if (counter == 2000)
00376 {
00377 current_position = static_cast<double>(node->getTPDOValue<int32_t>("measured_position")) / SchunkPowerBallNode::RAD_TO_STEPS_FACTOR;
00378 LOGGING_INFO (CanOpen, "Current position: " << current_position << endl);
00379 node->enableNode(ds402::MOO_INTERPOLATED_POSITION_MODE);
00380 }
00381
00382 if (counter >= 2005)
00383 {
00384 double starting_point = asin(current_position);
00385 target_position = sin(0.01*(counter-2005) + starting_point);
00386 LOGGING_INFO (CanOpen, "Sinus target: " << target_position << endl);
00387 node->setTarget(target_position);
00388 }
00389
00390 if (counter == 48)
00391 {
00392
00393 }
00394 ++counter;
00395 }
00396
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 node->disableNode();
00479 node_8->disableNode();
00480
00481 return 0;
00482 }