pg70_example.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // This file is part of the SCHUNK Canopen Driver suite.
3 //
4 // This program is free software licensed under the LGPL
5 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
6 // You can find a copy of this license in LICENSE folder in the top
7 // directory of the source code.
8 //
9 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
10 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
11 // -- END LICENSE BLOCK ------------------------------------------------
12 
18 
19 using namespace icl_hardware::canopen_schunk;
20 int main (int argc, char* argv[])
21 {
22  // Initializing
24 
25  CanOpenController my_controller("auto");
26 
27  DS402Group::Ptr arm_group = my_controller.getGroup<DS402Group>();
28  my_controller.addNode<DS402Node>(12);
29 
30  DS402Node::Ptr node = my_controller.getNode<DS402Node>(12);
31 
33  my_controller.initNodes();
34 
35  node->printSupportedModesOfOperation();
36 
38  config.profile_acceleration = 1.0;
39  config.profile_velocity = 0.5;
40  config.use_relative_targets = false;
41  config.change_set_immediately = true;
42  config.use_blending = false;
43 
44 
45  node->setTransmissionFactor(65000);
46  node->setModeOfOperation(ds402::MOO_PROFILE_POSITION_MODE);
47  node->setDefaultPDOMapping(DS402Node::PDO_MAPPING_PROFILE_POSITION_MODE);
48 
49  float current_position;
50  float target_position = 0.2;
51 
52  my_controller.syncAll();
53 
54 
55  node->setupProfilePositionMode(config);
56  sleep(1);
57  node->enableNode(ds402::MOO_PROFILE_POSITION_MODE);
58  sleep(1);
59 
60  std::string target_string = "0.0";
61 
62  while (target_string != "q")
63  {
64  LOGGING_INFO(CanOpen, "Please insert a new target position (between 0 and 1, insert q to abort: " << endl);
65  std::cin >> target_string;
66  std::cout << std::endl;
67 
68  try
69  {
70  target_position = boost::lexical_cast<float>(target_string);
71  }
72  catch(boost::bad_lexical_cast &)
73  {
74  if (target_string != "q")
75  {
76  LOGGING_ERROR (CanOpen, "Invalid input! Please insert a numeric target or q to exit." << endl);
77  }
78  continue;
79  }
80 
81  node->setTarget(target_position);
82 
83  bool is_reached = false;
84 
85  size_t counter = 0;
86 
87  while ((!is_reached && counter > 5) || counter <= 5)
88  {
89  try {
90  my_controller.syncAll();
91  }
92  catch (const std::exception& e)
93  {
94  LOGGING_ERROR (CanOpen, e.what() << endl);
95  return -1;
96  }
97 
98  usleep(10000);
99 
100  if (counter > 2)
101  {
102  if (node)
103  {
104  try
105  {
106  node->printStatus();
107  is_reached = node->isTargetReached();
108  current_position = node->getTPDOValue<int32_t>("measured_position");
109  LOGGING_INFO (CanOpen, "Current position: " << current_position << endl);
110  }
111  catch (const std::exception& e)
112  {
113  LOGGING_ERROR (CanOpen, e.what() << endl);
114  return -1;
115  }
116  }
117  }
118 
119  if (counter == 5)
120  {
121  my_controller.enablePPMotion();
122  }
123  ++counter;
124  }
125 
126  LOGGING_INFO (CanOpen, "Target reached" << endl);
127  }
128 
129  node->disableNode();
130 
131  return 0;
132 }
signed int int32_t
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
Configuration parameters for a Profile_Position_Mode according to CiA DSP-402 V1.1 section 12...
Definition: ds402.h:169
int main(int argc, char *argv[])
#define LOGGING_INFO(streamname, arg)
void initNodes(const int16_t node_id=-1)
Initializes a node with a given ID or all nodes.
config
The DS402Group class is the base class for canOpen devices implementing the DS402 device protocol (mo...
Definition: DS402Group.h:45
bool use_blending
If set to true, the device will blend over to a new setpoint. Defaults to true.
Definition: ds402.h:213
#define LOGGING_ERROR(streamname, arg)
unsigned int sleep(unsigned int seconds)
The CanOpenController class is the main entry point for any calls to the canOpen System.
void enablePPMotion(const int16_t node_id=-1)
When using the ProfilePositionMode is used, in addition to setting the target motion has to be trigge...
boost::shared_ptr< NodeT > getNode(const uint8_t node_id)
Returns a shared pointer handle to a node.
bool use_relative_targets
This parameter influences the interpretation of new set points. If set to true, new set point positio...
Definition: ds402.h:207
float profile_acceleration
This will be used for both acceleration ramps.
Definition: ds402.h:179
ThreadStream & endl(ThreadStream &stream)
virtual void setDefaultPDOMapping(const eDefaultPDOMapping mapping)
Choose one of the predefined default mappings. Please see the enum eDefaultPDOMapping for a list of a...
Definition: DS402Node.cpp:44
boost::shared_ptr< GroupT > getGroup(const std::string &index="default")
Returns a shared pointer to the group with a given index if possible.
void addNode(const uint8_t node_id, const std::string &group_name="default")
Adds a new node to a group. If the group is not found (e.g. it was not created before), nothing will be done.
bool change_set_immediately
If this is set to true the device will not ramp down at a setpoint if a following one is given...
Definition: ds402.h:199
Class that holds devices according to the DS402 (drives and motion control) specification.
Definition: DS402Node.h:43
void syncAll()
Downloads all the RPDOs, Sends a Sync and Uploads all the TPDOs.
int usleep(unsigned long useconds)


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Mon Jun 10 2019 15:07:49