Code for the mbed NXP LPC1768 To be used on The Robot Studio Slave Boards License : Simplified BSD

Dependencies:   mbed

Committer:
rrknight
Date:
Wed Mar 06 17:07:47 2013 +0000
Revision:
1:b430b4401fc4
Parent:
0:18d7499b82f3
Child:
2:7ab1d5918efe
hannover work in progress

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rrknight 0:18d7499b82f3 1 #ifndef EPOSCMD_H
rrknight 0:18d7499b82f3 2 #define EPOSCMD_H
rrknight 0:18d7499b82f3 3
rrknight 0:18d7499b82f3 4 //includes
rrknight 0:18d7499b82f3 5 #include "mbed.h"
rrknight 0:18d7499b82f3 6 #include <stdint.h>
rrknight 0:18d7499b82f3 7
rrknight 0:18d7499b82f3 8 #include "registers.h"
rrknight 0:18d7499b82f3 9
rrknight 0:18d7499b82f3 10 //Define
rrknight 0:18d7499b82f3 11 #define NUMBER_MAX_EPOS2_PER_SLAVE 15
rrknight 1:b430b4401fc4 12 #define NUMBER_MSG_PER_PACKET 45
rrknight 1:b430b4401fc4 13 #define NUMBER_BYTES_PER_MSG 8
rrknight 1:b430b4401fc4 14 #define NUMBER_EPOS2_BOARDS 1
rrknight 1:b430b4401fc4 15 #define NB_SAMPLES_MEDIAN 5
rrknight 1:b430b4401fc4 16 //#define NB_MSG_TO_TRACK 20 //at least 4
rrknight 1:b430b4401fc4 17 //#define CMD_BUFFER_SIZE 26 //13*2 -> 2 cmdSet of 13 cmds each
rrknight 1:b430b4401fc4 18 #define PAUSE 10
rrknight 1:b430b4401fc4 19 #define EPOS2_OK 0
rrknight 1:b430b4401fc4 20 #define EPOS2_ERROR -1
rrknight 1:b430b4401fc4 21 #define LOOP_PERIOD_TIME 20000 //20 ms
rrknight 0:18d7499b82f3 22
rrknight 0:18d7499b82f3 23 enum ActivatedMode
rrknight 0:18d7499b82f3 24 {
rrknight 0:18d7499b82f3 25 POSITION = 0,
rrknight 0:18d7499b82f3 26 CURRENT = 1,
rrknight 0:18d7499b82f3 27 VELOCITY = 2,
rrknight 0:18d7499b82f3 28 PROFILE_POSITION = 3,
rrknight 0:18d7499b82f3 29 FORCE = 4
rrknight 0:18d7499b82f3 30 };
rrknight 0:18d7499b82f3 31
rrknight 0:18d7499b82f3 32 //global variables
rrknight 0:18d7499b82f3 33 extern CAN cantoepos;
rrknight 0:18d7499b82f3 34 extern Serial pc;
rrknight 0:18d7499b82f3 35 //extern Serial pc;
rrknight 0:18d7499b82f3 36 extern DigitalOut ledchain[]; //used for debugging
rrknight 0:18d7499b82f3 37 extern char data[8];
rrknight 0:18d7499b82f3 38 //extern unsigned int count[12]; //used for debugging
rrknight 0:18d7499b82f3 39 extern ActivatedMode activMode[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 40
rrknight 0:18d7499b82f3 41 //ADC variables
rrknight 0:18d7499b82f3 42 extern AnalogIn an1;
rrknight 0:18d7499b82f3 43 extern AnalogIn an2;
rrknight 0:18d7499b82f3 44 extern AnalogIn an3;
rrknight 0:18d7499b82f3 45 extern AnalogIn an4;
rrknight 0:18d7499b82f3 46 extern AnalogIn an5;
rrknight 0:18d7499b82f3 47 extern AnalogIn an6;
rrknight 0:18d7499b82f3 48
rrknight 0:18d7499b82f3 49 //sensor variables
rrknight 0:18d7499b82f3 50 extern int32_t encPosition[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 51 //extern int16_t potiPosArray[NUMBER_EPOS2_BOARDS][5];
rrknight 0:18d7499b82f3 52 extern int16_t potiPosArray[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 53 extern int16_t medPotiPosition[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 54 extern int16_t avgCurrent[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 55 extern int16_t medForce[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 56 extern int32_t velocity[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 57
rrknight 0:18d7499b82f3 58 extern int8_t boardStatus[NUMBER_EPOS2_BOARDS];
rrknight 0:18d7499b82f3 59
rrknight 0:18d7499b82f3 60 //Multiplexer address lines
rrknight 0:18d7499b82f3 61 extern DigitalOut A0;
rrknight 0:18d7499b82f3 62 extern DigitalOut A1;
rrknight 0:18d7499b82f3 63 extern DigitalOut A2;
rrknight 0:18d7499b82f3 64
rrknight 0:18d7499b82f3 65 //functions
rrknight 0:18d7499b82f3 66 void setMultiplexerChannel(const int8_t);
rrknight 0:18d7499b82f3 67 static void setNMT(const int8_t, uint8_t);
rrknight 0:18d7499b82f3 68 static int8_t setObjectSDO(const int8_t, const int32_t, int32_t);
rrknight 0:18d7499b82f3 69 static int8_t setPDO(const int8_t, uint16_t, uint8_t, uint32_t, uint8_t);
rrknight 0:18d7499b82f3 70
rrknight 0:18d7499b82f3 71 //EPOS2 boards and Motor settings
rrknight 0:18d7499b82f3 72 //static void setMotorType(const int8_t);
rrknight 0:18d7499b82f3 73 //static void setPolePair(const int8_t);
rrknight 0:18d7499b82f3 74 //static void setMaximalMotorSpeed(const int8_t);
rrknight 0:18d7499b82f3 75 //static void setMaximalProfileVelocity(const int8_t);
rrknight 0:18d7499b82f3 76 //static void setMaxAcceleration(const int8_t);
rrknight 0:18d7499b82f3 77 //static void setThermalTimeConstantWinding(const int8_t);
rrknight 0:18d7499b82f3 78 //static void setMaximalFollowingError(const int8_t);
rrknight 0:18d7499b82f3 79
rrknight 0:18d7499b82f3 80 static int8_t setModeOfOperation(const int8_t, uint8_t);
rrknight 0:18d7499b82f3 81 extern void setModeOfOperationPDO(const int8_t, uint8_t);
rrknight 0:18d7499b82f3 82
rrknight 0:18d7499b82f3 83 static void shutdownControlword(const int8_t);
rrknight 0:18d7499b82f3 84 extern void shutdownControlwordIT(const int8_t);
rrknight 0:18d7499b82f3 85 static void switchOnEnableOperationControlword(const int8_t);
rrknight 0:18d7499b82f3 86 extern void switchOnEnableOperationControlwordIT(const int8_t);
rrknight 0:18d7499b82f3 87 extern void faultResetControlword(const int8_t);
rrknight 0:18d7499b82f3 88 //static void reEnableControlword(const int8_t);
rrknight 0:18d7499b82f3 89
rrknight 0:18d7499b82f3 90 //macro functions
rrknight 0:18d7499b82f3 91 extern int8_t initEposBoard(const int8_t);
rrknight 0:18d7499b82f3 92 extern void setCurrent(const int8_t, const int16_t);
rrknight 0:18d7499b82f3 93 extern void setPosition(const int8_t, const int32_t);
rrknight 0:18d7499b82f3 94 extern void setVelocity(const int8_t, const int32_t);
rrknight 0:18d7499b82f3 95 extern void setForce(const int8_t, const int16_t);
rrknight 0:18d7499b82f3 96
rrknight 0:18d7499b82f3 97 extern void getPosition(const int8_t);
rrknight 0:18d7499b82f3 98 extern void getCurrent(const int8_t);
rrknight 0:18d7499b82f3 99 extern void getVelocity(const int8_t);
rrknight 0:18d7499b82f3 100 extern int16_t getForce(const int8_t);
rrknight 0:18d7499b82f3 101 extern void getPotiPosition(const int8_t);
rrknight 0:18d7499b82f3 102 extern void getIncEnc1CntIdxPls(const int8_t); //get Incremental Encoder 1 Counter at Index Pulse
rrknight 0:18d7499b82f3 103
rrknight 0:18d7499b82f3 104 extern void getStatusword(const int8_t);
rrknight 0:18d7499b82f3 105
rrknight 0:18d7499b82f3 106 #endif //EPOSCMD_H