Working Maveric

Committer:
mettrque
Date:
Tue Aug 22 10:49:39 2017 +0000
Revision:
10:36a2131f636c
Parent:
6:ef95300898b2
last military version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mettrque 0:bdca5e4773dd 1 /*
mettrque 0:bdca5e4773dd 2 * MaxonEPOS4.h
mettrque 0:bdca5e4773dd 3 * Copyright (c) 2017, ZHAW
mettrque 0:bdca5e4773dd 4 * All rights reserved.
mettrque 0:bdca5e4773dd 5 *
mettrque 10:36a2131f636c 6 * Created on: 06.06.2017
mettrque 10:36a2131f636c 7 * Author: Quentin Mettraux
mettrque 0:bdca5e4773dd 8 */
mettrque 0:bdca5e4773dd 9
mettrque 0:bdca5e4773dd 10 #ifndef MAXON_EPOS4_H_
mettrque 0:bdca5e4773dd 11 #define MAXON_EPOS4_H_
mettrque 0:bdca5e4773dd 12
mettrque 0:bdca5e4773dd 13 #include <cstdlib>
mettrque 0:bdca5e4773dd 14 #include <stdint.h>
mettrque 0:bdca5e4773dd 15 #include <mbed.h>
mettrque 0:bdca5e4773dd 16 #include "CANopen.h"
mettrque 0:bdca5e4773dd 17 #include "Signal.h"
mettrque 0:bdca5e4773dd 18
mettrque 0:bdca5e4773dd 19 /**
mettrque 0:bdca5e4773dd 20 * The MaxonEPOS4 class is a device driver for maxon motor EPOS4 servo controllers.
mettrque 0:bdca5e4773dd 21 * It uses a CANopen object to communicate with the servo controller, and offers
mettrque 0:bdca5e4773dd 22 * methods to enable or disable the device, to set a desired torque value and to
mettrque 0:bdca5e4773dd 23 * read the actual position value of the drive.
mettrque 0:bdca5e4773dd 24 */
mettrque 0:bdca5e4773dd 25 class MaxonEPOS4 : public CANopen::Delegate {
mettrque 0:bdca5e4773dd 26
mettrque 0:bdca5e4773dd 27 public:
mettrque 0:bdca5e4773dd 28
mettrque 0:bdca5e4773dd 29 MaxonEPOS4(CANopen& canOpen, uint32_t nodeID, float period);
mettrque 0:bdca5e4773dd 30 virtual ~MaxonEPOS4();
mettrque 0:bdca5e4773dd 31 void setEnable(bool enable);
mettrque 0:bdca5e4773dd 32 bool isEnabled();
mettrque 0:bdca5e4773dd 33 void writeTorque(int16_t targetTorque);
mettrque 6:ef95300898b2 34 void writeVelocity(int32_t targetVelocity);
mettrque 0:bdca5e4773dd 35 int32_t readPositionValue();
mettrque 10:36a2131f636c 36 uint16_t readI2tValue();
mettrque 0:bdca5e4773dd 37
mettrque 0:bdca5e4773dd 38 private:
mettrque 0:bdca5e4773dd 39
mettrque 0:bdca5e4773dd 40 static const uint32_t STACK_SIZE = 1024; // stack size of thread, given in [bytes]
mettrque 0:bdca5e4773dd 41
mettrque 0:bdca5e4773dd 42 static const uint16_t SHUTDOWN = 0x0006; // predefined controlwords (object 0x6040)
mettrque 0:bdca5e4773dd 43 static const uint16_t SWITCH_ON = 0x0007;
mettrque 0:bdca5e4773dd 44 static const uint16_t DISABLE_VOLTAGE = 0x0000;
mettrque 0:bdca5e4773dd 45 static const uint16_t QUICK_STOP = 0x0002;
mettrque 0:bdca5e4773dd 46 static const uint16_t DISABLE_OPERATION = 0x0007;
mettrque 0:bdca5e4773dd 47 static const uint16_t ENABLE_OPERATION = 0x000F;
mettrque 0:bdca5e4773dd 48 static const uint16_t FAULT_RESET = 0x0080;
mettrque 0:bdca5e4773dd 49
mettrque 0:bdca5e4773dd 50 static const uint16_t NOT_READY_TO_SWITCH_ON = 0x0000; // predefined statuswords (object 0x6041)
mettrque 0:bdca5e4773dd 51 static const uint16_t SWITCH_ON_DISABLED = 0x0040;
mettrque 0:bdca5e4773dd 52 static const uint16_t READY_TO_SWITCH_ON = 0x0021;
mettrque 0:bdca5e4773dd 53 static const uint16_t SWITCHED_ON = 0x0023;
mettrque 0:bdca5e4773dd 54 static const uint16_t OPERATION_ENABLED = 0x0027;
mettrque 0:bdca5e4773dd 55 static const uint16_t QUICK_STOP_ACTIVE = 0x0007;
mettrque 0:bdca5e4773dd 56 static const uint16_t FAULT_REACTION_ACTIVE = 0x000F;
mettrque 0:bdca5e4773dd 57 static const uint16_t FAULT = 0x0008;
mettrque 0:bdca5e4773dd 58
mettrque 10:36a2131f636c 59 static const uint16_t STATUSWORD_MASK = 0x086F; // bitmask for statusword
mettrque 0:bdca5e4773dd 60 static const int8_t CYCLIC_SYNCHRONOUS_TORQUE_MODE = 10; // modes of operation
mettrque 6:ef95300898b2 61 static const int8_t PROFILE_VELOCITY_MODE = 3; // modes of operation
mettrque 0:bdca5e4773dd 62
mettrque 0:bdca5e4773dd 63 CANopen& canOpen;
mettrque 0:bdca5e4773dd 64 uint32_t nodeID;
mettrque 0:bdca5e4773dd 65 bool enable;
mettrque 0:bdca5e4773dd 66 int16_t targetTorque;
mettrque 6:ef95300898b2 67 int32_t targetVelocity;
mettrque 0:bdca5e4773dd 68 uint16_t statusword;
mettrque 0:bdca5e4773dd 69 int32_t positionActualValue;
mettrque 10:36a2131f636c 70 uint16_t i2tActualValue;
mettrque 0:bdca5e4773dd 71 Signal signal;
mettrque 0:bdca5e4773dd 72 Thread thread;
mettrque 0:bdca5e4773dd 73 Ticker ticker;
mettrque 0:bdca5e4773dd 74
mettrque 0:bdca5e4773dd 75 void receiveObject(uint32_t functionCode, uint8_t object[]);
mettrque 0:bdca5e4773dd 76 void sendSignal();
mettrque 0:bdca5e4773dd 77 void run();
mettrque 0:bdca5e4773dd 78 };
mettrque 0:bdca5e4773dd 79
mettrque 0:bdca5e4773dd 80 #endif /* MAXON_EPOS4_H_ */
mettrque 0:bdca5e4773dd 81