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
00077 if (!canopen::openConnection(deviceFile,canopen::baudRate)){
00078 std::cout << "Cannot open CAN device; aborting." << std::endl;
00079 exit(EXIT_FAILURE);
00080 }
00081 else{
00082 std::cout << "Connection to CAN bus established" << std::endl;
00083 }
00084
00085 canopen::devices[ CANid ] = canopen::Device(CANid);
00086 canopen::syncInterval = std::chrono::milliseconds(static_cast<int>(10.0));
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, chainName, canopen::syncInterval);
00100 std::this_thread::sleep_for(std::chrono::milliseconds(100));
00101
00102 canopen::setOperationMode(CANid, canopen::MODES_OF_OPERATION_HOMING_MODE);
00103
00104 canopen::controlPDO((uint16_t)CANid, canopen::CONTROLWORD_ENABLE_OPERATION | canopen::CONTROLWORD_START_HOMING, 0x00);
00105
00106 std::this_thread::sleep_for(std::chrono::milliseconds(500));
00107 std::cout << "Homing complete" << std::endl;
00108 }