seed3_command.h
Go to the documentation of this file.
1 #ifndef SEED_COMMAND_H_
2 #define SEED_COMMAND_H_
3 
4 #include <boost/asio.hpp>
5 #include <boost/thread.hpp>
6 #include <vector>
7 #include <unordered_map>
8 
9 using namespace boost::asio;
10 
11 namespace seed
12 {
13  namespace controller
14  {
16  {
17  public:
20 
21  bool openPort(std::string _port, unsigned int _baud_rate);
22  void closePort();
23  void writeBuffer(std::vector<char>& _send_data);
24  std::string readBuffer(uint16_t _wait_time=0);
25  void flushPort();
26 
27  void readBufferAsync(std::string _delim, uint16_t _timeout=50);
28  void onReceive(const boost::system::error_code& _error, size_t _bytes_transferred);
29  void can_receive(std::vector<uint8_t>& _receive_data);
30  //--------- Receive timer event ------
31  void onTimer(const boost::system::error_code& _error);
32 
33  std::string receive_buffer_;
34 
35  private:
36  io_service io_;
37  serial_port serial_;
38  deadline_timer timer_;
39 
40  boost::mutex serial_mtx_;
41 
43  boost::asio::streambuf stream_buffer_;
44 
45  };
46 
47  class SeedCommand{
48  public:
49  SeedCommand();
50  ~SeedCommand();
51 
52  bool is_open_;
53 
54  bool openPort(std::string _port, unsigned int _baud_rate);
55  void closePort();
56  void openCom();
57  void closeCom();
58  void writeSerialCommand(uint8_t _id, uint8_t *_data);
59  void writeSerialCommand(uint8_t _id, uint8_t _line, uint8_t *_data);
60  bool readSerialCommand(std::vector<uint8_t>& _receive_data, uint16_t _timeout=50);
61 
62  //seed_information
63  std::unordered_map<std::string, int32_t> seed_info_;
64  std::unordered_map<std::string, int32_t> operational_info_;
65  std::unordered_map<std::string, int16_t> lock_code_info_;
66  std::vector<uint8_t> connected_id_;
67 
68  int str2int(std::string _data);
69 
70  //Fixed Parameters---------
71  void setTypeNumber(uint8_t _id, const char* _type);
72  void setEditorVersion(uint8_t _id, const char* _ver);
73  void setMotorCurrentParam(uint8_t _id, uint16_t _driver_max, uint16_t _motor_max, uint8_t _current_conversion);
74  void setDummy(uint8_t _id, uint8_t _cmd);
75  void setSerialVersion(uint8_t _id, const char* _ver);
76  void setMotorAdaptation(uint8_t _id, uint32_t _type, uint16_t _volt);
77  void setCurrentInstantaneous(uint8_t _id, uint16_t _max, uint16_t _time);
78  void setFirmwareVersion(uint8_t _id, const char* _ver);
79  void setMotorParam(uint8_t _id, uint8_t _mode, uint8_t _feedback);
80  void setEncoderParam(uint8_t _id, uint16_t _encoder_pulse, uint16_t _motor_pulse);
81 
82  //Base Parameters---------
83  void setIdParam(uint8_t _id, uint8_t _re_id);
84  void setEmergencyParam(uint8_t _id, uint8_t _mode, uint8_t _io_no, uint8_t _io, uint8_t _reset);
85  void setStopModeParam(uint8_t _id, uint8_t _motor, uint8_t _script);
86  void setOperationParam(uint8_t _id, uint8_t _auto_run, uint8_t _script, uint8_t _point_go, uint8_t _motor, uint8_t _io);
87  void setOvertravelParam(uint8_t _id, uint8_t _mode, uint8_t _minus, uint8_t _plus, uint8_t _io);
88  void setErrorMotionParam(uint8_t _id, uint8_t _temperature, uint8_t _motor, uint8_t _ot, uint8_t _voltage);
89  void setResponseParam(uint8_t _id, uint8_t _mode);
90  void setDioParam(uint8_t _id, uint8_t _io0, uint8_t _io1, uint8_t _io2, uint8_t _io3);
91  void setAdParam(uint8_t _id, uint8_t _ad0, uint8_t _ad1, uint8_t _ad2, uint8_t _ad3);
92 
93  //Motor Settings---------
94  void setMotorCurrent(uint8_t _id, uint16_t _max, uint8_t _min, uint16_t _min_time);
95  void setMotorMaxSpeed(uint8_t _id, uint16_t _speed);
96  void setMotorControlParameter1(uint8_t _id, uint8_t _back_surge_a, uint8_t _back_surge_b, uint8_t _back_surge_c, uint8_t _oc, uint8_t _fst);
97  void setMotorControlParameter1(uint8_t _id, uint16_t _i_gain, uint8_t _d_gain, uint8_t _switch);
98  void setInPosition(uint8_t _id, uint16_t _value);
99  void setAcDecelerationRate(uint8_t _id, uint16_t _acc, uint16_t _dec);
100  void setMotorControlParameter2(uint8_t _id, uint16_t _initial_speed, uint16_t _p_gain, uint8_t _correcting_gain);
101  void setUpperSoftwareLimit(uint8_t _id, int32_t _limit);
102  void setLowerSoftwareLimit(uint8_t _id, int32_t _limit);
103  void setMotorRotation(uint8_t _id, uint8_t _pulse_division, uint8_t _encoder_division, uint8_t _motor_inverted, uint8_t _encoder_inverted, uint8_t _dc_inverted);
104  void setMotorError(uint8_t _id, uint16_t _time, uint32_t _pulse);
105  void setMotorErrorLimit(uint8_t _id, uint8_t _temerature , uint8_t _minimum_voltage, uint8_t _maximum_voltage, uint8_t _current);
106 
107  //Script Settings-----
108  void setScriptData(uint8_t _id, uint8_t _number , uint8_t _start_line, uint8_t _end_line);
109  void writeScriptLine(uint8_t _id, uint8_t _line , const char* _command);
110 
111  //Other-------
112  bool getLockCode(uint8_t _id, uint8_t _mode);
113  void setReleaseLock(uint8_t _id, uint8_t _type, uint16_t _code);
114  std::vector<uint8_t> getConnectedId();
115  void writeRom(uint8_t _id, uint8_t type);
116  int io2int(std::string _parameter);
117 
118  //run motor command------
119  std::array<int, 3> getPosition(uint8_t _id);
120  std::array<int, 3> getCurrent(uint8_t _id);
121  std::array<int, 6> getOperationalInfo(uint8_t _id);
122 
123  void onServo(uint8_t _id, uint8_t _state);
124  void stopMotor(uint8_t _id);
125  void runScript(uint8_t _id, uint8_t _script_no);
126  void waitForScriptEnd(int _number);
127  void actuateRelativePositionByTime(uint8_t _id, int16_t _time, int32_t _position);
128  void actuateRelativePositionBySpeed(uint8_t _id, int16_t _speed, int32_t _position);
129  void actuateAbsolutePositionByTime(uint8_t _id, uint16_t _time, int32_t _position);
130  void actuateAbsolutePositionBySpeed(uint8_t _id, int16_t _speed, int32_t _position);
131  void actuateContinuousRelativePosition(uint8_t _id, uint16_t _time, int32_t _position);
132  void actuateContinuousAbsolutePosition(uint8_t _id, uint16_t _time, int32_t _position);
133  void actuateBySpeed(uint8_t _id, int16_t _speed);
134 
135  void setPosition(uint8_t _id, uint8_t _position, uint8_t _state);
136 
137  private:
138  //Value
139  unsigned int check_sum_,count_,length_;
140  std::vector<uint8_t> send_data_;
141 
142  protected:
144  };
145 
146  } //end namespce controller
147 } //end namespace seed
148 
149 #endif
SerialCommunication serial_com_
boost::asio::streambuf stream_buffer_
Definition: seed3_command.h:43
std::unordered_map< std::string, int32_t > operational_info_
Definition: seed3_command.h:64
std::vector< uint8_t > connected_id_
Definition: seed3_command.h:66
std::vector< uint8_t > send_data_
std::unordered_map< std::string, int16_t > lock_code_info_
Definition: seed3_command.h:65
std::unordered_map< std::string, int32_t > seed_info_
Definition: seed3_command.h:63


seed_smartactuator_sdk
Author(s):
autogenerated on Mon Nov 2 2020 03:39:20