CORC Project
CANOpen Robot Controller Software Documentation
testJoints.cpp
Go to the documentation of this file.
1 
12 #include <iostream>
13 
14 #include "ActuatedJoint.h"
15 #include "CANopen.h"
16 #include "CopleyDrive.h"
17 #include "Drive.h"
18 #include "DummyActJoint.h"
19 #include "Joint.h"
20 
21 pthread_mutex_t CO_CAN_VALID_mtx = PTHREAD_MUTEX_INITIALIZER;
22 volatile uint32_t CO_timer1ms = 0U;
23 
24 /* Helper functions ***********************************************************/
25 void CO_errExit(char *msg) {
26  perror(msg);
27  exit(EXIT_FAILURE);
28 }
29 
30 /* send CANopen generic emergency message */
31 void CO_error(const uint32_t info) {
32  CO_errorReport(CO->em, CO_EM_GENERIC_SOFTWARE_ERROR, CO_EMC_SOFTWARE_INTERNAL, info);
33  fprintf(stderr, "canopend generic error: 0x%X\n", info);
34 }
35 
36 int main() {
37  std::cout << "This is a script to test the implementation of the Joints, ActuatedJoints and Drive Classes! \n";
38 
39  std::cout << "1. Construct a CopleyDrive Object (which implements Drive Class) \n";
40  // Construct different types of joints
41  Drive *testDrive = new CopleyDrive(100);
42 
43  std::cout << "2. Construct a TestActJoint Object (Cast as a ActuatedJoint), using the testDrive Object \n";
44  ActuatedJoint *normalJoint = new DummyActJoint(1, -1, 1, testDrive);
45 
46  std::cout << "Read the ID of the Joint (Expected Value 1): " << normalJoint->getId() << "\n";
47  std::cout << "Read Node ID of the Drive (Expected Value 100): " << testDrive->getNodeID() << "\n";
48 
49  std::cout << "Read Value of the Joint (Expected Value 0): " << normalJoint->getQ() << "\n";
50  motorProfile testProfile{4000000, 240000, 240000};
51  std::cout << "Set the Joint into Position Control Mode: " << normalJoint->setMode(POSITION_CONTROL, testProfile) << "\n";
52 
53  std::cout << "Set the position of the Joint to 1 (expected result: true): " << normalJoint->setPosition(1) << "\n";
54 
55  std::cout << "Read Value of the Joint (Expected Value 0): " << normalJoint->getQ() << "\n";
56 
57  std::cout << "Call a updateValue() defined in Joint: " << normalJoint->updateValue() << "\n";
58 
59  std::cout << "Read Value of the Joint (Expected Value 1): " << normalJoint->getQ() << "\n";
60  //test velocity control commands
61 
62  std::cout << "Set the Joint into Velocity Control Mode: " << normalJoint->setMode(VELOCITY_CONTROL, testProfile) << "\n";
63 
64  std::cout << "Set the position of the Joint to 1 (expected result: true): " << normalJoint->setVelocity(100) << "\n";
65 
66  std::cout << "Read Value of the Joint (Expected Value 0): " << normalJoint->getQ() << "\n";
67 
68  std::cout << "Call a updateValue() defined in Joint: " << normalJoint->updateValue() << "\n";
69 
70  std::cout << "Read Value of the Joint (Expected Value 1): " << normalJoint->getQ() << "\n";
71  return 0;
72 }
int main()
Definition: testJoints.cpp:36
int getNodeID()
Get returns the CanNode ID.
Definition: Drive.cpp:17
Abstract class describing a Drive used to communicate with a CANbus device. Note that many functions ...
Definition: Drive.h:105
volatile uint32_t CO_timer1ms
Definition: testJoints.cpp:22
void CO_errExit(char *msg)
Definition: testJoints.cpp:25
Example implementation of the ActuatedJoints class.
Definition: DummyActJoint.h:22
A dummy class to test whether the actuated joint inheritence stuff works.
The ActuatedJoint class is a abstract class which represents a joint in a Robot objec. This class implements the Joint class, and specifically represents a joint which is actuated. This therefore requires a Drive object which will be used to interact with the physical hardware.
virtual ControlMode setMode(ControlMode driveMode_, motorProfile profile)
Set the mode of the device (nominally, position, velocity or torque control)
An implementation of the Drive Object, specifically for the Copley Drive.
double getQ()
Returns the internal value of the joint (e.g. Angle, length, depending on joint type) ...
Definition: Joint.cpp:30
The Joint class is a abstract class which represents a joint in a Robot objec. This class can be used...
Abstract class representing an actuated joint in a Robot Class (extending joint). Requires a Drive ob...
Definition: ActuatedJoint.h:47
unsigned int uint32_t
Definition: CO_command.h:31
An implementation of the Drive Object, specifically for Copley-branded devices (currently used on the...
Definition: CopleyDrive.h:23
virtual setMovementReturnCode_t setPosition(double desQ)
Set the Position object.
struct to hold desired velocity, acceleration and deceleration values for a drives motor controller p...
Definition: Drive.h:94
virtual setMovementReturnCode_t setVelocity(double velocity)
Sets a velocity set point (in joint units)
The Drive class is used to interface with a CANOpen motor drive. According to the CiA402 standard...
virtual bool updateValue()=0
Updates the value of the joint. This will read the value from hardware, and update the software&#39;s cur...
pthread_mutex_t CO_CAN_VALID_mtx
Definition: testJoints.cpp:21
int getId()
Get the Id object.
Definition: Joint.cpp:26
void CO_error(const uint32_t info)
Definition: testJoints.cpp:31