22 DEBUG_OUT(
"Drive " << this->
NodeID <<
" Writing " << position <<
" to 0x607A");
23 *(&CO_OD_RAM.targetMotorPositions.motor1 + ((this->
NodeID - 1))) = position;
28 DEBUG_OUT(
"Drive " <<
NodeID <<
" Writing " << velocity <<
" to 0x60FF");
38 int q = *(&CO_OD_RAM.targetMotorPositions.motor1 + ((this->
NodeID - 1)));
51 *(&CO_OD_RAM.controlWords.motor1 + ((this->
NodeID - 1))) = 0x06;
56 *(&CO_OD_RAM.controlWords.motor1 + ((this->
NodeID - 1))) = 0x0F;
61 *(&CO_OD_RAM.controlWords.motor1 + ((this->
NodeID - 1))) = 0x00;
75 int controlWord = *(&CO_OD_RAM.controlWords.motor1 + ((this->
NodeID - 1)));
76 *(&CO_OD_RAM.controlWords.motor1 + ((this->
NodeID - 1))) = controlWord ^ 0x10;
77 if ((controlWord & 0x10) > 0) {
108 int COB_ID = 0x100 * PDO_Num + 0x80 +
NodeID;
111 std::vector<std::string> CANCommands;
114 std::stringstream sstream;
117 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1800 + PDO_Num - 1 <<
" 1 u32 0x" << std::hex << 0x800000000 + COB_ID;
118 CANCommands.push_back(sstream.str());
119 sstream.str(std::string());
122 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1A00 + PDO_Num - 1 <<
" 0 u8 0";
123 CANCommands.push_back(sstream.str());
124 sstream.str(std::string());
127 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1800 + PDO_Num - 1 <<
" 2 u8 0x" << SyncRate;
128 CANCommands.push_back(sstream.str());
129 sstream.str(std::string());
131 for (
int i = 1; i <= items.size(); i++) {
133 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1A00 + PDO_Num - 1 <<
" " << i <<
" u32 0x" << std::hex << OD_Addresses[items[i - 1]] * 0x10000 + OD_Data_Size[items[i - 1]];
134 CANCommands.push_back(sstream.str());
135 sstream.str(std::string());
139 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1A00 + PDO_Num - 1 <<
" 0 u8 " << items.size();
140 CANCommands.push_back(sstream.str());
141 sstream.str(std::string());
144 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1800 + PDO_Num - 1 <<
" 1 u32 0x" << std::hex << COB_ID;
145 CANCommands.push_back(sstream.str());
146 sstream.str(std::string());
155 int COB_ID = 0x100 * PDO_Num +
NodeID;
158 std::vector<std::string> CANCommands;
162 std::stringstream sstream;
164 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1400 + PDO_Num - 1 <<
" 1 u32 0x" << std::hex << 0x800000000 + COB_ID;
165 CANCommands.push_back(sstream.str());
166 sstream.str(std::string());
169 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1600 + PDO_Num - 1 <<
" 0 u8 0";
170 CANCommands.push_back(sstream.str());
171 sstream.str(std::string());
174 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1400 + PDO_Num - 1 <<
" 2 u8 0x" << UpdateTiming;
175 CANCommands.push_back(sstream.str());
176 sstream.str(std::string());
178 for (
int i = 1; i <= items.size(); i++) {
180 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1600 + PDO_Num - 1 <<
" " << i <<
" u32 0x" << std::hex << OD_Addresses[items[i - 1]] * 0x10000 + OD_Data_Size[items[i - 1]];
181 CANCommands.push_back(sstream.str());
182 sstream.str(std::string());
186 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1600 + PDO_Num - 1 <<
" 0 u8 " << items.size();
187 CANCommands.push_back(sstream.str());
188 sstream.str(std::string());
191 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x1400 + PDO_Num - 1 <<
" 1 u32 0x" << std::hex << COB_ID;
192 CANCommands.push_back(sstream.str());
193 sstream.str(std::string());
200 std::vector<std::string> CANCommands;
202 std::stringstream sstream;
204 sstream <<
"[1] " <<
NodeID <<
" start";
205 CANCommands.push_back(sstream.str());
206 sstream.str(std::string());
208 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x6060 <<
" 0 i8 1";
209 CANCommands.push_back(sstream.str());
210 sstream.str(std::string());
213 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x6081 <<
" 0 i32 " << positionProfile.
profileVelocity;
214 CANCommands.push_back(sstream.str());
215 sstream.str(std::string());
218 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x6083 <<
" 0 i32 " << positionProfile.
profileAccelration;
219 CANCommands.push_back(sstream.str());
220 sstream.str(std::string());
223 sstream <<
"[1] " << NodeID <<
" write 0x" << std::hex << 0x6084 <<
" 0 i32 " << positionProfile.
profileDeceleration;
224 CANCommands.push_back(sstream.str());
225 sstream.str(std::string());
235 int successfulMessages = 1;
236 for (
auto strCommand : messages) {
238 char *SDO_Message = (
char *)(strCommand.c_str());
253 return successfulMessages;
DriveState driveState
State of the drive.
virtual bool setPos(int position)
int getNodeID()
Get returns the CanNode ID.
virtual DriveState getDriveState()
Get the current state of the drive.
virtual bool enable()
Sets the state of the drive to "enabled".
virtual int updateDriveStatus()
virtual bool disable()
sets the state of the drive to "disabled"
int error
Current error state of the drive.
virtual bool setTorque(int torque)
virtual bool initPDOs()
Initialises a standard set of PDOs for the use of the drive. These are:
int NodeID
The CAN Node ID used to address this particular drive on the CAN bus.
std::vector< std::string > generateTPDOConfigSDO(std::vector< OD_Entry_t > items, int PDO_Num, int SyncRate)
Generates the list of commands required to configure TPDOs on the drives.
virtual bool readyToSwitchOn()
Changes the state of the drive to "ready to switch on".
Drive()
Construct a new Drive object.
struct to hold desired velocity, acceleration and deceleration values for a drives motor controller p...
virtual bool setVel(int velocity)
int sendSDOMessages(std::vector< std::string > messages)
messages Properly formatted SDO Messages
std::vector< std::string > generateRPDOConfigSDO(std::vector< OD_Entry_t > items, int PDO_Num, int UpdateTiming)
Generates the list of commands required to configure RPDOs on the drives.
virtual bool posControlConfirmSP()
Flips Bit 4 of Control Word (0x6041) - A new set point is only confirmed if the transition is from 0 ...
void cancomm_socketFree(char *command, char *ret)
int statusWord
Current status word of the drive.
std::vector< std::string > generatePosControlConfigSDO(motorProfile positionProfile)
Generates the list of commands required to configure Position control in CANopen motor drive...