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

Dependencies:   mbed

Committer:
therobotstudio
Date:
Wed Feb 11 16:18:15 2015 +0000
Revision:
6:8a0250a4877a
Parent:
4:396433e30e64
v1.0.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
therobotstudio 6:8a0250a4877a 1 /*
therobotstudio 6:8a0250a4877a 2 * Copyright (c) 2013, The Robot Studio
therobotstudio 6:8a0250a4877a 3 * All rights reserved.
therobotstudio 6:8a0250a4877a 4 *
therobotstudio 6:8a0250a4877a 5 * Redistribution and use in source and binary forms, with or without
therobotstudio 6:8a0250a4877a 6 * modification, are permitted provided that the following conditions are met:
therobotstudio 6:8a0250a4877a 7 *
therobotstudio 6:8a0250a4877a 8 * * Redistributions of source code must retain the above copyright notice, this
therobotstudio 6:8a0250a4877a 9 * list of conditions and the following disclaimer.
therobotstudio 6:8a0250a4877a 10 *
therobotstudio 6:8a0250a4877a 11 * * Redistributions in binary form must reproduce the above copyright notice,
therobotstudio 6:8a0250a4877a 12 * this list of conditions and the following disclaimer in the documentation
therobotstudio 6:8a0250a4877a 13 * and/or other materials provided with the distribution.
therobotstudio 6:8a0250a4877a 14 *
therobotstudio 6:8a0250a4877a 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
therobotstudio 6:8a0250a4877a 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
therobotstudio 6:8a0250a4877a 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
therobotstudio 6:8a0250a4877a 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
therobotstudio 6:8a0250a4877a 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
therobotstudio 6:8a0250a4877a 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
therobotstudio 6:8a0250a4877a 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
therobotstudio 6:8a0250a4877a 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
therobotstudio 6:8a0250a4877a 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
therobotstudio 6:8a0250a4877a 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
therobotstudio 6:8a0250a4877a 25 *
therobotstudio 6:8a0250a4877a 26 * Created on: Feb 27, 2013
therobotstudio 6:8a0250a4877a 27 * Author: Cyril Jourdan (cyril.jourdan@therobotstudio.com)
therobotstudio 6:8a0250a4877a 28 */
therobotstudio 6:8a0250a4877a 29
rrknight 0:18d7499b82f3 30 #ifndef EPOSCMD_H
rrknight 0:18d7499b82f3 31 #define EPOSCMD_H
rrknight 0:18d7499b82f3 32
therobotstudio 6:8a0250a4877a 33 /*** Includes ***/
rrknight 0:18d7499b82f3 34 #include "mbed.h"
rrknight 0:18d7499b82f3 35 #include <stdint.h>
rrknight 0:18d7499b82f3 36 #include "registers.h"
rrknight 0:18d7499b82f3 37
therobotstudio 6:8a0250a4877a 38 /*** Define s ***/
rrknight 0:18d7499b82f3 39 #define NUMBER_MAX_EPOS2_PER_SLAVE 15
rrknight 1:b430b4401fc4 40 #define NUMBER_MSG_PER_PACKET 45
rrknight 1:b430b4401fc4 41 #define NUMBER_BYTES_PER_MSG 8
rrknight 3:c16d726670b2 42 #define NUMBER_EPOS2_BOARDS 15
rrknight 1:b430b4401fc4 43 #define NB_SAMPLES_MEDIAN 5
rrknight 1:b430b4401fc4 44 //#define NB_MSG_TO_TRACK 20 //at least 4
rrknight 1:b430b4401fc4 45 //#define CMD_BUFFER_SIZE 26 //13*2 -> 2 cmdSet of 13 cmds each
rrknight 1:b430b4401fc4 46 #define PAUSE 10
rrknight 1:b430b4401fc4 47 #define EPOS2_OK 0
rrknight 1:b430b4401fc4 48 #define EPOS2_ERROR -1
rrknight 3:c16d726670b2 49 #define LOOP_PERIOD_TIME 25000 //25 ms - 40Hz
rrknight 3:c16d726670b2 50 #define TIMEOUT 10000
rrknight 0:18d7499b82f3 51
rrknight 0:18d7499b82f3 52 enum ActivatedMode
rrknight 0:18d7499b82f3 53 {
rrknight 0:18d7499b82f3 54 POSITION = 0,
rrknight 0:18d7499b82f3 55 CURRENT = 1,
rrknight 0:18d7499b82f3 56 VELOCITY = 2,
rrknight 0:18d7499b82f3 57 PROFILE_POSITION = 3,
rrknight 0:18d7499b82f3 58 FORCE = 4
rrknight 0:18d7499b82f3 59 };
rrknight 0:18d7499b82f3 60
rrknight 0:18d7499b82f3 61 //global variables
rrknight 0:18d7499b82f3 62 extern CAN cantoepos;
rrknight 0:18d7499b82f3 63 extern Serial pc;
rrknight 0:18d7499b82f3 64 //extern Serial pc;
rrknight 0:18d7499b82f3 65 extern DigitalOut ledchain[]; //used for debugging
rrknight 0:18d7499b82f3 66 extern char data[8];
rrknight 0:18d7499b82f3 67 //extern unsigned int count[12]; //used for debugging
rrknight 3:c16d726670b2 68 extern ActivatedMode activMode[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 0:18d7499b82f3 69
rrknight 0:18d7499b82f3 70 //ADC variables
rrknight 0:18d7499b82f3 71 extern AnalogIn an1;
rrknight 0:18d7499b82f3 72 extern AnalogIn an2;
rrknight 0:18d7499b82f3 73 extern AnalogIn an3;
rrknight 0:18d7499b82f3 74 extern AnalogIn an4;
rrknight 0:18d7499b82f3 75 extern AnalogIn an5;
rrknight 0:18d7499b82f3 76 extern AnalogIn an6;
rrknight 0:18d7499b82f3 77
rrknight 0:18d7499b82f3 78 //sensor variables
rrknight 3:c16d726670b2 79 extern int32_t encPosition[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 3:c16d726670b2 80 //extern int16_t potiPosArray[NUMBER_MAX_EPOS2_PER_SLAVE][5];
rrknight 3:c16d726670b2 81 extern int16_t potiPosArray[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 3:c16d726670b2 82 extern int16_t medPotiPosition[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 3:c16d726670b2 83 extern int16_t avgCurrent[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 3:c16d726670b2 84 extern int16_t medForce[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 3:c16d726670b2 85 extern int32_t velocity[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 0:18d7499b82f3 86
rrknight 3:c16d726670b2 87 extern int8_t boardStatus[NUMBER_MAX_EPOS2_PER_SLAVE];
rrknight 0:18d7499b82f3 88
rrknight 0:18d7499b82f3 89 //Multiplexer address lines
rrknight 0:18d7499b82f3 90 extern DigitalOut A0;
rrknight 0:18d7499b82f3 91 extern DigitalOut A1;
rrknight 0:18d7499b82f3 92 extern DigitalOut A2;
rrknight 0:18d7499b82f3 93
rrknight 0:18d7499b82f3 94 //functions
rrknight 0:18d7499b82f3 95 void setMultiplexerChannel(const int8_t);
rrknight 0:18d7499b82f3 96 static void setNMT(const int8_t, uint8_t);
rrknight 4:396433e30e64 97 extern int8_t setObjectSDO(const int8_t, const int32_t, int32_t);
rrknight 0:18d7499b82f3 98 static int8_t setPDO(const int8_t, uint16_t, uint8_t, uint32_t, uint8_t);
rrknight 0:18d7499b82f3 99
rrknight 0:18d7499b82f3 100 //EPOS2 boards and Motor settings
rrknight 0:18d7499b82f3 101 //static void setMotorType(const int8_t);
rrknight 0:18d7499b82f3 102 //static void setPolePair(const int8_t);
rrknight 0:18d7499b82f3 103 //static void setMaximalMotorSpeed(const int8_t);
rrknight 0:18d7499b82f3 104 //static void setMaximalProfileVelocity(const int8_t);
rrknight 0:18d7499b82f3 105 //static void setMaxAcceleration(const int8_t);
rrknight 0:18d7499b82f3 106 //static void setThermalTimeConstantWinding(const int8_t);
rrknight 0:18d7499b82f3 107 //static void setMaximalFollowingError(const int8_t);
rrknight 0:18d7499b82f3 108
rrknight 0:18d7499b82f3 109 static int8_t setModeOfOperation(const int8_t, uint8_t);
rrknight 0:18d7499b82f3 110 extern void setModeOfOperationPDO(const int8_t, uint8_t);
rrknight 0:18d7499b82f3 111
rrknight 0:18d7499b82f3 112 static void shutdownControlword(const int8_t);
rrknight 0:18d7499b82f3 113 extern void shutdownControlwordIT(const int8_t);
rrknight 0:18d7499b82f3 114 static void switchOnEnableOperationControlword(const int8_t);
rrknight 0:18d7499b82f3 115 extern void switchOnEnableOperationControlwordIT(const int8_t);
rrknight 0:18d7499b82f3 116 extern void faultResetControlword(const int8_t);
rrknight 0:18d7499b82f3 117 //static void reEnableControlword(const int8_t);
rrknight 0:18d7499b82f3 118
rrknight 0:18d7499b82f3 119 //macro functions
rrknight 0:18d7499b82f3 120 extern int8_t initEposBoard(const int8_t);
rrknight 0:18d7499b82f3 121 extern void setCurrent(const int8_t, const int16_t);
rrknight 0:18d7499b82f3 122 extern void setPosition(const int8_t, const int32_t);
rrknight 0:18d7499b82f3 123 extern void setVelocity(const int8_t, const int32_t);
rrknight 0:18d7499b82f3 124 extern void setForce(const int8_t, const int16_t);
rrknight 0:18d7499b82f3 125
rrknight 0:18d7499b82f3 126 extern void getPosition(const int8_t);
rrknight 0:18d7499b82f3 127 extern void getCurrent(const int8_t);
rrknight 0:18d7499b82f3 128 extern void getVelocity(const int8_t);
rrknight 0:18d7499b82f3 129 extern int16_t getForce(const int8_t);
rrknight 0:18d7499b82f3 130 extern void getPotiPosition(const int8_t);
rrknight 0:18d7499b82f3 131 extern void getIncEnc1CntIdxPls(const int8_t); //get Incremental Encoder 1 Counter at Index Pulse
rrknight 0:18d7499b82f3 132
rrknight 0:18d7499b82f3 133 extern void getStatusword(const int8_t);
rrknight 0:18d7499b82f3 134
rrknight 0:18d7499b82f3 135 #endif //EPOSCMD_H