Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef MANUS_ARM_HPP_
00008 #define MANUS_ARM_HPP_
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <sys/types.h>
00013 #include <sys/socket.h>
00014 #include <sys/ioctl.h>
00015 #include <net/if.h>
00016 #include <linux/can.h>
00017 #include <linux/can/raw.h>
00018 #include <string>
00019 #include <sstream>
00020 #include <string.h>
00021 #include <boost/thread.hpp>
00022 #include <exception>
00023 #include <vector>
00024 #include <time.h>
00025 #include "movement_definitions.h"
00026
00027
00028
00029
00030 #define STAT_NONE 0
00031
00032 #define STAT_WARNING 1
00033 #define MSG_GRIPPER_STUCK 0
00034 #define MSG_WRONG_AREA 1
00035 #define MSG_ARM_FOLDED_STRETCHED 2
00036 #define MSG_BLOCKED_MOTOR 3
00037 #define MSG_MAX_ROT 4
00038
00039 #define STAT_GENERAL 2
00040 #define MSG_FOLDED 0
00041 #define MSG_UNFOLDED 1
00042 #define MSG_GRIPPER_INIT 2
00043 #define MSG_ABS_MEASURE 3
00044
00045 #define STAT_ERROR 3
00046 #define MSG_IO_80C552 1
00047 #define MSG_ABS_ENCODER 4
00048 #define MSG_MOVE_WITHOUT_INPUT 15
00049
00050 #define CBOX_0_INIT 0x370
00051 #define CBOX_1_CARTESIAN 0x371
00052 #define CBOX_4_JOINT 0x374
00053 #define CBOX_5_UNFOLD 0x375
00054 #define CBOX_6_FOLD 0x376
00055
00056
00057
00058
00059 #define CARTESIAN_SLOP 300
00060
00061
00062
00063 #define CARTESIAN_FOOT 13854.54
00064
00065
00066 const int SPEED_LIMITS[][5] = { { 3, 10, 17, 23, 30 },
00067 { 10, 30, 50, 70, 90 },
00068 { 10, 30, 50, 70, 90 },
00069 { 1, 3, 5, 7, 9 },
00070 { 1, 3, 5, 7, 9 },
00071 { 1, 3, 5, 7, 9 },
00072 { 1, 4, 7, 10, 14 } };
00073
00074 int sign(int n)
00075 {
00076 return ((n >= 0) ? 1 : -1);
00077 }
00078
00079 float sign(float n)
00080 {
00081 return ((n >= 0) ? 1.0f : -1.0f);
00082 }
00083
00087 struct armState
00088 {
00089 bool isValid;
00090 int jointPositions[7];
00091 int cbox;
00092 std::string message;
00093 };
00094
00101 class ManusArm
00102 {
00103 private:
00104
00105 ManusArm();
00106 ManusArm(ManusArm const&){};
00107 ManusArm& operator=(ManusArm const&);
00108
00109 static ManusArm* armInstance;
00110
00111
00112 int canSock;
00113 bool running;
00114 void pollCanSocket();
00115
00116
00117 armState currState;
00118 bool moveComplete;
00119 boost::mutex stateMutex;
00120 void setCbox(int cbox, can_frame* frm);
00121
00122
00123 void sendFrames(can_frame frame);
00124 std::vector<can_frame> sendQueue;
00125 void enqueueFrame(can_frame toSend);
00126
00127
00128 void setCartesian();
00129
00130
00131 boost::thread motionThread;
00132 void doCartesianMove(const CartesianMove& cmd);
00133 void doConstantMove(const ConstantMove& cmd);
00134
00135 public:
00136 static ManusArm* instance();
00137 int init(std::string interface);
00138 std::string getPrintState();
00139 std::string getCsvState();
00140 void getPosition(float position[]);
00141 bool isMoveComplete() { return moveComplete; }
00142 void setMoveComplete(bool move_complete)
00143 {
00144 boost::mutex::scoped_lock lock(stateMutex);
00145 moveComplete = move_complete;
00146 }
00147
00148
00149 void fold();
00150 void unfold();
00151 void moveCartesian(const CartesianMove& cmd);
00152 void moveConstant(const ConstantMove& cmd);
00153 };
00154
00155 class ArmException: public std::exception
00156 {
00157 private:
00158 char* msg;
00159 public:
00160 ArmException(char* message) throw();
00161 virtual const char* what() const throw();
00162 };
00163
00164 #endif