Go to the documentation of this file.00001
00060 #include <utility>
00061 #include "ipa_canopen_core/canopen.h"
00062
00063 int main(int argc, char *argv[]) {
00064
00065 if (argc != 4) {
00066 std::cout << "Arguments:" << std::endl
00067 << "(1) device file" << std::endl
00068 << "(2) CAN deviceID" << std::endl
00069 << "(3) Baud Rate" << std::endl
00070 << "Example: ./homing /dev/pcan32 12 500K" << std::endl;
00071 return -1;
00072 }
00073 std::string deviceFile = std::string(argv[1]);
00074 uint16_t CANid = std::stoi(std::string(argv[2]));
00075 canopen::baudRate = std::string(argv[3]);
00076 canopen::syncInterval = std::chrono::milliseconds(static_cast<int>(10.0));
00077
00078 if (!canopen::openConnection(deviceFile,canopen::baudRate)){
00079 std::cout << "Cannot open CAN device; aborting." << std::endl;
00080 exit(EXIT_FAILURE);
00081 }
00082 else{
00083 std::cout << "Connection to CAN bus established" << std::endl;
00084 }
00085
00086 canopen::devices[ CANid ] = canopen::Device(CANid);
00087
00088 canopen::incomingPDOHandlers[ 0x180 + CANid ] = [CANid](const TPCANRdMsg m) { canopen::defaultPDO_incoming_status( CANid, m ); };
00089 canopen::incomingPDOHandlers[ 0x480 + CANid ] = [CANid](const TPCANRdMsg m) { canopen::defaultPDO_incoming_pos( CANid, m ); };
00090 canopen::sendPos = canopen::defaultPDOOutgoing_interpolated;
00091
00092 std::string chainName = "test_chain";
00093 std::vector <uint8_t> ids;
00094 ids.push_back(CANid);
00095 std::vector <std::string> j_names;
00096 j_names.push_back("joint_1");
00097 canopen::deviceGroups[ chainName ] = canopen::DeviceGroup(ids, j_names);
00098
00099 canopen::init(deviceFile, canopen::syncInterval);
00100
00101 canopen::sendSDO(CANid, canopen::MODES_OF_OPERATION, canopen::MODES_OF_OPERATION_HOMING_MODE);
00102 std::this_thread::sleep_for(std::chrono::milliseconds(100));
00103 canopen::sendSDO(CANid, canopen::CONTROLWORD, (uint16_t) (canopen::CONTROLWORD_ENABLE_OPERATION | canopen::CONTROLWORD_START_HOMING));
00104 std::this_thread::sleep_for(std::chrono::milliseconds(500));
00105 std::cout << "Homing complete" << std::endl;
00106 }