00001 // Copyright (c) 2012 Fraunhofer Institute 00002 // for Manufacturing Engineering and Automation (IPA) 00003 // See the file license.txt for copying permission. 00004 00005 // This program performs homing (referencing) of a device. 00006 // See the user manual for details: 00007 // https://github.com/ipa-tys/canopen/blob/master/doc/usermanual.pdf?raw=true 00008 00009 #include <utility> 00010 #include "canopen.h" 00011 00012 int main(int argc, char *argv[]) { 00013 00014 if (argc != 3) { 00015 std::cout << "Arguments:" << std::endl 00016 << "(1) device file" << std::endl 00017 << "(2) CAN deviceID" << std::endl 00018 << "Example: ./homing /dev/pcan32 12" << std::endl; 00019 return -1; 00020 } 00021 std::string deviceFile = std::string(argv[1]); 00022 uint16_t CANid = std::stoi(std::string(argv[2])); 00023 00024 // configure CANopen device objects and custom incoming and outgoing PDOs: 00025 00026 canopen::devices[ CANid ] = canopen::Device(CANid); 00027 canopen::init(deviceFile, std::chrono::milliseconds(10)); 00028 00029 canopen::sendSDO(CANid, canopen::modes_of_operation, 00030 canopen::modes_of_operation_homing_mode); 00031 canopen::sendSDO(CANid, canopen::controlword, 00032 (uint16_t) (canopen::controlword_enable_operation | 00033 canopen::controlword_start_homing)); 00034 std::this_thread::sleep_for(std::chrono::milliseconds(500)); 00035 }