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