example.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <threemxl/example.h>
00003 #include <threemxl/C3mxlROS.h>
00004 
00005 void DxlROSExample::init(char *path)
00006 {
00007   CDxlConfig *config = new CDxlConfig();
00008 
00009   if (path)
00010   {
00011     ROS_INFO("Using shared_serial");
00012     motor_ = new C3mxlROS(path);
00013   }
00014   else
00015   {
00016     ROS_INFO("Using direct connection");
00017     motor_ = new C3mxl();
00018     
00019     serial_port_.port_open("/dev/ttyUSB0", LxSerial::RS485_FTDI);
00020     serial_port_.set_speed(LxSerial::S921600);
00021     motor_->setSerialPort(&serial_port_);
00022   }
00023 
00024   motor_->setConfig(config->setID(109));
00025   motor_->init(false);
00026   motor_->set3MxlMode(TORQUE_MODE);
00027 
00028   delete config;
00029 }
00030 
00031 void DxlROSExample::spin()
00032 {
00033   ros::Rate loop_rate(1); //herz;
00034   int dir = -1;
00035 
00036   while (ros::ok())
00037   {
00038     motor_->setTorque(dir*0.005); // nM
00039     
00040     dir = -dir;
00041     loop_rate.sleep();
00042   }
00043   
00044   motor_->setTorque(0);
00045 }
00046 
00047 int main(int argc, char **argv)
00048 {
00049   ros::init(argc, argv, "dxl_ros_example");
00050 
00051   char *path=NULL;
00052   if (argc == 2)
00053     path = argv[1];
00054  
00055   DxlROSExample dxl_ros_example;
00056   
00057   dxl_ros_example.init(path);
00058   dxl_ros_example.spin();
00059   
00060   return 0;   
00061 } 


threemxl
Author(s):
autogenerated on Thu Jun 6 2019 21:10:52