CORC Project
CANOpen Robot Controller Software Documentation
testRobot.cpp
Go to the documentation of this file.
1 
11 #include "ExoRobot.h"
12 //using namespace std;
13 
14 #include "CANopen.h"
15 
16 pthread_mutex_t CO_CAN_VALID_mtx = PTHREAD_MUTEX_INITIALIZER;
17 volatile uint32_t CO_timer1ms = 0U;
18 
19 /* Helper functions ***********************************************************/
20 void CO_errExit(char *msg) {
21  perror(msg);
22  exit(EXIT_FAILURE);
23 }
24 
25 /* send CANopen generic emergency message */
26 void CO_error(const uint32_t info) {
27  CO_errorReport(CO->em, CO_EM_GENERIC_SOFTWARE_ERROR, CO_EMC_SOFTWARE_INTERNAL, info);
28  fprintf(stderr, "canopend generic error: 0x%X\n", info);
29 }
30 
31 int main(void) {
32  //TODO add keyboard initializer to initiRobot.
33  //INITINPUT
34  // Create Exo object + initialise derived Joints + trajectory Generator
35  cout << ">>> Creating ExoRobot" << endl;
36  ExoRobot exo;
37  exo.start();
38  // print joint positions
39  cout
40  << ">>> Current Robot Position (expected value: all joints 0) >>>" << endl;
41  exo.printStatus();
42  //print trajectoryGenerator params
43 
44  cout << ">>> Print Trajectory Parameters (Expected Value 0.2, 0)>>>" << endl;
45  exo.printTrajectoryParam();
46  //Load new trajParams and print out
47  cout << ">>> Load new Trajectory Parameters >>>" << endl;
48  exo.setTrajectory();
49  cout << ">>> Print Trajectory Parameters (Expected Value ???? ) >>>" << endl;
50  exo.printTrajectoryParam();
51 
52  //Try to move through trajectory without being in correct mode
53  /* cout << ">>> Moving Through Trajectory (Expected Result: False) >>>" << endl
54  << exo.moveThroughTraj() << endl;*/
55 
56  // Initialise Position Control
57  cout << ">>> Initialsing Position Control >>> \n"
58  << exo.initPositionControl() << endl;
59 
60  /* cout << ">>> Moving Through Trajectory (Expected Result: True) >>>" << endl
61  << exo.moveThroughTraj() << endl;*/
62 
63  cout << ">>> Current Robot Position (expected value: all joints 0) >>>" << endl;
64  exo.printStatus();
65 
66  cout << ">>> Updating all Joint Values >>>" << endl;
67  exo.updateRobot();
68 
69  cout << ">>> Current Robot Position (expected value: all joints 100 + Joint ID) >>>" << endl;
70  exo.printStatus();
71 
72  // NON BLOCKING KEYBOARD INPUT - quits when q is pressed
73  cout << "Test keyboard input w/ w,a,s,d,x. Type q to exit keyboard test" << endl;
74  while (!exo.keyboard.getQ()) {
75  usleep(500000);
76  exo.updateRobot();
77  if (!exo.moveThroughTraj()) {
78  std::cout << "PRESS A to move through traj" << std::endl;
79  } else {
80  std::cout << "Trajectory complete" << std::endl;
81  }
82  if (exo.keyboard.getS()) {
83  exo.startNewTraj();
84  exo.setSpecificTrajectory(RobotMode::SITDWN);
85  }
86  if (exo.keyboard.getW()) {
87  exo.setSpecificTrajectory(RobotMode::NORMALWALK);
88  }
89  //exo.printTrajectoryParam();
90  //exo.keyboard.clearCurrentStates();
91  exo.printStatus();
92  }
93 
94  // exit(0);
95 }
bool initPositionControl()
Initialises all joints to position control mode.
Definition: ExoRobot.cpp:16
Example implementation of the Robot class, representing an X2 Exoskeleton, using DummyActuatedJoint a...
Definition: ExoRobot.h:36
int main(void)
Definition: testRobot.cpp:31
bool getS()
Getter method for private S key state.
Definition: Keyboard.cpp:110
bool moveThroughTraj()
For each joint, move through(send appropriate commands to joints) the Currently generated trajectory ...
Definition: ExoRobot.cpp:45
pthread_mutex_t CO_CAN_VALID_mtx
Definition: testRobot.cpp:16
volatile uint32_t CO_timer1ms
Definition: testRobot.cpp:17
unsigned int uint32_t
Definition: CO_command.h:31
void printStatus()
print out status of robot and all of its joints
Definition: Robot.cpp:44
void startNewTraj()
Begin a new trajectory with the currently loaded trajectory paramaters. Using the ExoRobot current co...
Definition: ExoRobot.cpp:37
bool getQ()
Getter method for private Q key state.
Definition: Keyboard.cpp:122
void CO_error(const uint32_t info)
Definition: testRobot.cpp:26
bool getW()
Getter method for private W key state.
Definition: Keyboard.cpp:116
Keyboard keyboard
Definition: ExoRobot.h:57
void CO_errExit(char *msg)
Definition: testRobot.cpp:20
void updateRobot()
update current state of the robot, including input and output devices. Overloaded Method from the Rob...
Definition: ExoRobot.cpp:115