mapping.cpp
Go to the documentation of this file.
00001 
00060 #include <utility>
00061 #include <iostream>
00062 #include <iomanip>
00063 #include "ipa_canopen_core/canopen.h"
00064 #include <sstream>
00065 
00066 int main(int argc, char *argv[])
00067 {
00068 
00069     if (argc != 4) {
00070         std::cout << "Arguments:" << std::endl
00071                   << "(1) device file" << std::endl
00072                   << "(2) CAN deviceID" << std::endl
00073                   << "(3) Baud Rate" << std::endl
00074                   << "Example: ./elmo_mapping /dev/pcan32 12 500K" << std::endl;
00075         return -1;
00076     }
00077 
00078 
00079 
00080     canopen::NMTmsg.ID = 0;
00081     canopen::NMTmsg.MSGTYPE = 0x00;
00082     canopen::NMTmsg.LEN = 2;
00083 
00084     canopen::syncMsg.ID = 0x80;
00085     canopen::syncMsg.MSGTYPE = 0x00;
00086 
00087     canopen::syncMsg.LEN = 0x00;
00088 
00089     std::string deviceFile = std::string(argv[1]);
00090     canopen::baudRate = std::string(argv[3]);
00091 
00092     if (!canopen::openConnection(deviceFile,canopen::baudRate)){
00093         std::cout << "Cannot open CAN device; aborting." << std::endl;
00094         exit(EXIT_FAILURE);
00095     }
00096     else{
00097         std::cout << "Connection to CAN bus established" << std::endl;
00098     }
00099 
00100     uint16_t CANid = std::stoi(std::string(argv[2]));
00101 
00102     canopen::devices[ CANid ] = canopen::Device(CANid);
00103     std::this_thread::sleep_for(std::chrono::milliseconds(10));
00104     canopen::sendNMT(CANid, canopen::NMT_RESET_NODE);
00105     std::this_thread::sleep_for(std::chrono::milliseconds(10000));;
00106     canopen::sendNMT(CANid, canopen::NMT_START_REMOTE_NODE);
00107     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
00108 
00109     std::this_thread::sleep_for(std::chrono::milliseconds(10));
00110 
00111     canopen::setObjects();
00112 
00113     TPCANMsg mes;
00114 
00115     std::cout << "Initialized the PDO mapping" << std::endl;
00116 
00117     for(int pdo_object=0;pdo_object<=3;pdo_object++)
00118     {
00119         canopen::disableTPDO(pdo_object);
00120         std::this_thread::sleep_for(std::chrono::milliseconds(100));
00121 
00122         canopen::clearTPDOMapping(pdo_object);
00123         std::this_thread::sleep_for(std::chrono::milliseconds(100));
00124 
00125         canopen::disableRPDO(pdo_object);
00126         std::this_thread::sleep_for(std::chrono::milliseconds(100));
00127 
00128         canopen::clearRPDOMapping(pdo_object);
00129         std::this_thread::sleep_for(std::chrono::milliseconds(100));
00130     }
00131 
00132     if(canopen::use_limit_switch)
00133     {
00134 
00135         std::vector<std::string> tpdo1_registers {"604100", "60FD00"};
00136         std::vector<int> tpdo1_sizes {0x10,0x20};
00137 
00138         canopen::makeTPDOMapping(0,tpdo1_registers, tpdo1_sizes, u_int8_t(0xFF));
00139     }
00140     else
00141     {
00142         std::vector<std::string> tpdo1_registers {"604100", "606100"};
00143         std::vector<int> tpdo1_sizes {0x10,0x08};
00144 
00145         canopen::makeTPDOMapping(0,tpdo1_registers, tpdo1_sizes, u_int8_t(0xFF));
00146 
00147     }
00148     std::this_thread::sleep_for(std::chrono::milliseconds(100));
00149 
00150     std::vector<std::string> tpdo4_registers {"606400", "606C00"};
00151     std::vector<int> tpdo4_sizes {0x20,0x20};
00152 
00153     canopen::makeTPDOMapping(3, tpdo4_registers, tpdo4_sizes, u_int8_t(0x01));
00154     std::this_thread::sleep_for(std::chrono::milliseconds(100));
00155 
00156     std::vector<std::string> rpdo1_registers {"604000"};
00157     std::vector<int> rpdo1_sizes {0x10};
00158 
00159     std::vector<std::string> rpdo2_registers {"60C101"};
00160     std::vector<int> rpdo2_sizes {0x20};
00161 
00162     canopen::makeRPDOMapping(0, rpdo1_registers, rpdo1_sizes, u_int8_t(0xFF));
00163     std::this_thread::sleep_for(std::chrono::milliseconds(100));
00164     canopen::makeRPDOMapping(1, rpdo2_registers, rpdo2_sizes, u_int8_t(0x01));
00165     std::this_thread::sleep_for(std::chrono::milliseconds(100));
00166 
00167     for(int pdo_object=0;pdo_object<=3;pdo_object++)
00168     {
00169         canopen::enableTPDO(pdo_object);
00170         std::this_thread::sleep_for(std::chrono::milliseconds(100));
00171 
00172         canopen::enableRPDO(pdo_object);
00173         std::this_thread::sleep_for(std::chrono::milliseconds(100));
00174     }
00175 
00176     std::this_thread::sleep_for(std::chrono::milliseconds(100));
00177 
00178 }


ipa_canopen_core
Author(s): Tobias Sing, Thiago de Freitas
autogenerated on Mon Oct 6 2014 00:59:25