minimal_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 
21 
22 int main (int argc, char* argv[])
23 {
24  // Initializing
26 
27  CanOpenController my_controller("auto");
28 
29  DS402Group::Ptr arm_group = my_controller.getGroup<DS402Group>();
30  my_controller.addNode<SchunkPowerBallNode>(3);
31  my_controller.addNode<SchunkPowerBallNode>(4);
32  my_controller.addNode<SchunkPowerBallNode>(5);
33  my_controller.addNode<SchunkPowerBallNode>(6);
34  my_controller.addNode<SchunkPowerBallNode>(7);
35  my_controller.addNode<SchunkPowerBallNode>(8);
36 
37 
38  arm_group->initNodes();
39  uint8_t nr = 8;
40  SchunkPowerBallNode::Ptr node = my_controller.getNode<SchunkPowerBallNode>(nr);
41 
43  config.profile_acceleration = 0.2;
44  config.profile_velocity = 0.2;
45  config.use_relative_targets = false;
46  config.change_set_immediately = true;
47  config.use_blending = true;
48 
49  arm_group->setupProfilePositionMode(config);
50 
51  std::vector<float> targets (6, 0.0);
52 
53 
54  arm_group->enableNodes();
55  sleep(1);
56  arm_group->setTarget(targets);
57  sleep(1);
58 // node->setTarget(0.3-targets[0]);
59 
60  std::vector<bool> foo;
61 
62  while (true)
63  {
64  try {
65  my_controller.syncAll();
66  }
67  catch (const std::exception& e)
68  {
69  LOGGING_ERROR (CanOpen, e.what() << endl);
70  return -1;
71  }
72  usleep(10000);
73 
74 // arm_group->printStatus(8);
75 
76  if (arm_group->isTargetReached(foo))
77  {
78  LOGGING_INFO (CanOpen, "All targets reached" << endl;);
79  break;
80  }
81  }
82 
83  arm_group->disableNodes();
84 
85  return 0;
86 }
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
#define LOGGING_INFO(streamname, arg)
This class gives a device specific interface for Schunk Powerballs, as they need some "special" treat...
config
The DS402Group class is the base class for canOpen devices implementing the DS402 device protocol (mo...
Definition: DS402Group.h:45
#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.
unsigned char uint8_t
boost::shared_ptr< NodeT > getNode(const uint8_t node_id)
Returns a shared pointer handle to a node.
ThreadStream & endl(ThreadStream &stream)
int main(int argc, char *argv[])
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.
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