Working Maveric

Committer:
mettrque
Date:
Tue May 30 21:11:54 2017 +0000
Revision:
6:ef95300898b2
Parent:
0:bdca5e4773dd
Child:
10:36a2131f636c
Working now

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 0:bdca5e4773dd 6 * Created on: 06.02.2017
mettrque 0:bdca5e4773dd 7 * Author: Marcel Honegger
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 0:bdca5e4773dd 36
mettrque 0:bdca5e4773dd 37 private:
mettrque 0:bdca5e4773dd 38
mettrque 0:bdca5e4773dd 39 static const uint32_t STACK_SIZE = 1024; // stack size of thread, given in [bytes]
mettrque 0:bdca5e4773dd 40
mettrque 0:bdca5e4773dd 41 static const uint16_t SHUTDOWN = 0x0006; // predefined controlwords (object 0x6040)
mettrque 0:bdca5e4773dd 42 static const uint16_t SWITCH_ON = 0x0007;
mettrque 0:bdca5e4773dd 43 static const uint16_t DISABLE_VOLTAGE = 0x0000;
mettrque 0:bdca5e4773dd 44 static const uint16_t QUICK_STOP = 0x0002;
mettrque 0:bdca5e4773dd 45 static const uint16_t DISABLE_OPERATION = 0x0007;
mettrque 0:bdca5e4773dd 46 static const uint16_t ENABLE_OPERATION = 0x000F;
mettrque 0:bdca5e4773dd 47 static const uint16_t FAULT_RESET = 0x0080;
mettrque 0:bdca5e4773dd 48
mettrque 0:bdca5e4773dd 49 static const uint16_t NOT_READY_TO_SWITCH_ON = 0x0000; // predefined statuswords (object 0x6041)
mettrque 0:bdca5e4773dd 50 static const uint16_t SWITCH_ON_DISABLED = 0x0040;
mettrque 0:bdca5e4773dd 51 static const uint16_t READY_TO_SWITCH_ON = 0x0021;
mettrque 0:bdca5e4773dd 52 static const uint16_t SWITCHED_ON = 0x0023;
mettrque 0:bdca5e4773dd 53 static const uint16_t OPERATION_ENABLED = 0x0027;
mettrque 0:bdca5e4773dd 54 static const uint16_t QUICK_STOP_ACTIVE = 0x0007;
mettrque 0:bdca5e4773dd 55 static const uint16_t FAULT_REACTION_ACTIVE = 0x000F;
mettrque 0:bdca5e4773dd 56 static const uint16_t FAULT = 0x0008;
mettrque 0:bdca5e4773dd 57
mettrque 0:bdca5e4773dd 58 static const uint16_t STATUSWORD_MASK = 0x006F; // bitmask for statusword
mettrque 0:bdca5e4773dd 59 static const int8_t CYCLIC_SYNCHRONOUS_TORQUE_MODE = 10; // modes of operation
mettrque 6:ef95300898b2 60 static const int8_t PROFILE_VELOCITY_MODE = 3; // modes of operation
mettrque 0:bdca5e4773dd 61
mettrque 0:bdca5e4773dd 62 CANopen& canOpen;
mettrque 0:bdca5e4773dd 63 uint32_t nodeID;
mettrque 0:bdca5e4773dd 64 bool enable;
mettrque 0:bdca5e4773dd 65 int16_t targetTorque;
mettrque 6:ef95300898b2 66 int32_t targetVelocity;
mettrque 0:bdca5e4773dd 67 uint16_t statusword;
mettrque 0:bdca5e4773dd 68 int32_t positionActualValue;
mettrque 0:bdca5e4773dd 69 Signal signal;
mettrque 0:bdca5e4773dd 70 Thread thread;
mettrque 0:bdca5e4773dd 71 Ticker ticker;
mettrque 0:bdca5e4773dd 72
mettrque 0:bdca5e4773dd 73 void receiveObject(uint32_t functionCode, uint8_t object[]);
mettrque 0:bdca5e4773dd 74 void sendSignal();
mettrque 0:bdca5e4773dd 75 void run();
mettrque 0:bdca5e4773dd 76 };
mettrque 0:bdca5e4773dd 77
mettrque 0:bdca5e4773dd 78 #endif /* MAXON_EPOS4_H_ */
mettrque 0:bdca5e4773dd 79