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

Dependencies:   mbed

include/eposCmd.h

Committer:
rrknight
Date:
2013-04-05
Revision:
4:396433e30e64
Parent:
3:c16d726670b2
Child:
6:8a0250a4877a

File content as of revision 4:396433e30e64:

#ifndef EPOSCMD_H
#define EPOSCMD_H

//includes
#include "mbed.h"
#include <stdint.h>

#include "registers.h"

//Define 
#define NUMBER_MAX_EPOS2_PER_SLAVE  15
#define NUMBER_MSG_PER_PACKET       45
#define NUMBER_BYTES_PER_MSG        8
#define NUMBER_EPOS2_BOARDS         15
#define NB_SAMPLES_MEDIAN           5
//#define NB_MSG_TO_TRACK             20 //at least 4
//#define CMD_BUFFER_SIZE             26 //13*2 -> 2 cmdSet of 13 cmds each
#define PAUSE                       10
#define EPOS2_OK                    0
#define EPOS2_ERROR                 -1
#define LOOP_PERIOD_TIME            25000 //25 ms - 40Hz
#define TIMEOUT                     10000

enum ActivatedMode
{
    POSITION = 0,
    CURRENT = 1,
    VELOCITY = 2,
    PROFILE_POSITION = 3,
    FORCE = 4
}; 

//global variables
extern CAN cantoepos;
extern Serial pc;
//extern Serial pc;
extern DigitalOut ledchain[];   //used for debugging
extern char data[8];
//extern unsigned int count[12];  //used for debugging
extern ActivatedMode activMode[NUMBER_MAX_EPOS2_PER_SLAVE];

//ADC variables
extern AnalogIn an1;
extern AnalogIn an2;
extern AnalogIn an3;
extern AnalogIn an4;
extern AnalogIn an5;
extern AnalogIn an6;

//sensor variables
extern int32_t encPosition[NUMBER_MAX_EPOS2_PER_SLAVE];
//extern int16_t potiPosArray[NUMBER_MAX_EPOS2_PER_SLAVE][5];
extern int16_t potiPosArray[NUMBER_MAX_EPOS2_PER_SLAVE];
extern int16_t medPotiPosition[NUMBER_MAX_EPOS2_PER_SLAVE];
extern int16_t avgCurrent[NUMBER_MAX_EPOS2_PER_SLAVE];
extern int16_t medForce[NUMBER_MAX_EPOS2_PER_SLAVE];
extern int32_t velocity[NUMBER_MAX_EPOS2_PER_SLAVE];

extern int8_t boardStatus[NUMBER_MAX_EPOS2_PER_SLAVE];

//Multiplexer address lines
extern DigitalOut A0;
extern DigitalOut A1;
extern DigitalOut A2;

//functions
void setMultiplexerChannel(const int8_t);
static void setNMT(const int8_t, uint8_t);
extern int8_t setObjectSDO(const int8_t, const int32_t, int32_t);
static int8_t setPDO(const int8_t, uint16_t, uint8_t, uint32_t, uint8_t);

//EPOS2 boards and Motor settings
//static void setMotorType(const int8_t);
//static void setPolePair(const int8_t);
//static void setMaximalMotorSpeed(const int8_t);
//static void setMaximalProfileVelocity(const int8_t);
//static void setMaxAcceleration(const int8_t);
//static void setThermalTimeConstantWinding(const int8_t);
//static void setMaximalFollowingError(const int8_t);

static int8_t setModeOfOperation(const int8_t, uint8_t);
extern void setModeOfOperationPDO(const int8_t, uint8_t);

static void shutdownControlword(const int8_t);
extern void shutdownControlwordIT(const int8_t);
static void switchOnEnableOperationControlword(const int8_t);
extern void switchOnEnableOperationControlwordIT(const int8_t);
extern void faultResetControlword(const int8_t);
//static void reEnableControlword(const int8_t);

//macro functions
extern int8_t initEposBoard(const int8_t);
extern void setCurrent(const int8_t, const int16_t);
extern void setPosition(const int8_t, const int32_t);
extern void setVelocity(const int8_t, const int32_t);
extern void setForce(const int8_t, const int16_t);

extern void getPosition(const int8_t);
extern void getCurrent(const int8_t);
extern void getVelocity(const int8_t);
extern int16_t getForce(const int8_t);
extern void getPotiPosition(const int8_t);
extern void getIncEnc1CntIdxPls(const int8_t); //get Incremental Encoder 1 Counter at Index Pulse

extern void getStatusword(const int8_t);

#endif //EPOSCMD_H