MyoSyn
A C++ library control synthetic muscles in tendon-driven robots
Loading...
Searching...
No Matches
myosyn.h
Go to the documentation of this file.
1#pragma once
2#ifndef MYOSYN_H
3#define MYOSYN_H
4
5#include <iostream>
6#include <quickDAQ.h>
7
8#define eprintf(_STR, ...) fprintf(ERRSTREAM, _STR, __VA_ARGS__)
9
10#define DIGITAL_HIGH_VOLTS 5.0
11#define DIGITAL_LOW_VOLTS 0.0
12#define WIND_UP_VOLTS 0.8
13#define WIND_DOWN_VOLTS 0.0
14#define DEFAULT_MUSCLE_TONE 1.0 // Newtons
15#define MAX_MUSCLE_TENSION 30.0 // Newtons
16#define MOTOR_SHAFT_DIAMTR 6 // millimeters
17#define LOADCELL_TARE_NSAMP 100
18
22typedef enum _DAQarrangement
23{
28
32typedef enum _muscleStatus
33{
39
40// myosyn global variables
41//extern int T5_quickDAQstatus;
43extern unsigned numConfiguredMuscles;
44extern int myosynLeader;
45extern double myosyn_samplingRate_global;
46
47// Some global reconfigurable DAQ configuration/pin mapping variables
48extern unsigned muscle_mtr_val [16][2];
49extern unsigned muscle_mtr_en [16][2];
50extern unsigned muscle_enc_ring [ 8][2];
51extern unsigned muscle_enc_kleo [ 8][2];
52extern unsigned muscle_enc_mtr [12][2];
53extern unsigned muscle_enc_spl [12][2];
54extern unsigned muscle_ld_cell [ 8][2];
55extern double loadcell_calib [ 8][2]; // gain, bias for each of 8 load cells
56extern double mtr_trque_calib [16][2]; // gain, bias for each of 8 load cells
57
58// Global myosyn functions
59
65unsigned myosynNumMuscles();
66
72
77void myosynSetConfiguration(DAQarrangement DAQconfiguration);
78
84double myosynSamplingRate(double newSamplingRate = myosyn_samplingRate_global);
85
89void myosynStart();
90
94void myosynStop();
95
100void myosynSetLeaderChannel(int newLeader);
101
107
111void myosynReadInputs();
112
116void myosynWriteOutputs();
117
122void myosynWaitForClock();
123
124// MyoSyn class
125
129class myosyn {
130 unsigned channelID;
131 DAQarrangement* myDAQarrangement;
132 muscleStatus status;
133
134 unsigned maxChannels_mtr, maxChannels_enc;
135
136 unsigned (*motor_enable_config)[2];
137 unsigned (*motor_value_config)[2];
138 unsigned (*encoder_config)[2];
139 unsigned (*encoder_opt_config)[2];
140 unsigned (*loadcell_config)[2];
141
142 // Muscle constant parameters for closed-loop control
143 double muscleToneTension;
144 double maxMuscleTension;
145
146 //Sensor and motor calibration parameters
147 double loadcell_offset, loadcell_gain; // Voltage to force calibration for loadcell
148 double encoder_offset_angle; // zero out encoder angle after windup
149 double encoder_angle_to_excursion_ratio; // Angle to tendon excursion calibration for encoder
150
151 double mtrTension_offset, mtrTension_gain; // Voltage to motor Tension
152
153 // Live update variables
154 double refMuscleTension;
155 double myMuscleTension;
156
157 // Controller variables
158 double motorCommand;
159
160public:
161 // Constructors and destructor
162
166 myosyn();
167
174 myosyn(unsigned muscleChannel);
175
176 ~myosyn();
177
178 // myosyn support functions
179
184 unsigned getChannelID();
185
191
196 void setMuscleStatus(muscleStatus newStatus);
197
198 // DAQ support functions and function pointers
199
204 void (*startDAQ)();
205
210 void (*stopDAQ)();
211
212 // Muscle open-loop operations
213
217 void windUp();
218
222 void windDown();
223
224 // Functions for muscle closed-loop parameter settings
225
231 void setMuscleToneTension(double myMuscleTone_value);
232
237 double getMuscleToneTension();
238
243 void setMaxMuscleTension(double max_tension);
244
249 double getMaxMuscleTension();
250
255 void setReferenceTension(double myTension);
256
262 double getReferenceTension();
263
264 // Functions to read and scale sensor data
265
271 void calibrateTension(double loadCellGain = NAN);
272
278 double loadcellV2F(double LCvoltage);
279
284 void readMuscleTension();
285
290 double getMuscleTension();
291
297 void calibrateExcursion(double spoolDiameter = NAN);
298
304 double encoderAngle2Excursion(double encoderAngle);
305
310 void readTendonExcursion();
311
316 double getTendonExcursion();
317
318 // Functions for controller and output write ops
319
324 void startMuscleControl();
325
330 double getMotorCommand();
331
336 void setMotorCommand(double newCommand);
337
341 void (*controlRoutine)(unsigned numOutputs, double* outputs, unsigned numInputs, double* inputs);
342
346 void executeControl();
347
352 void stopMuscleControl();
353};
354
356 T5encoder();
357};
358
359
361 T5control();
362};
363
364#endif // !MYOSYN_H
365
This is the class object for each muscle channel.
Definition: myosyn.h:129
void windUp()
Function starts/energizes the motor of the muscle channel to wind up the tendons to prevent slack.
Definition: myosyn.cpp:380
void stopMuscleControl()
Stops the force controller and update the status of the muscle channel. This function only needs to b...
Definition: myosyn.cpp:634
double getMaxMuscleTension()
Returns the upper limit of possible muscle tensions by the motor of the muscle channel.
Definition: myosyn.cpp:442
double getMuscleToneTension()
Returns the current muscle tone of the muscle channel.
Definition: myosyn.cpp:432
void setReferenceTension(double myTension)
The current reference/target muscle tension which the internal closed-loop controller will attempt to...
Definition: myosyn.cpp:447
double loadcellV2F(double LCvoltage)
Returns the force on the loadcell when supplied with the voltage based on the gain and bias set by ca...
Definition: myosyn.cpp:501
~myosyn()
Definition: myosyn.cpp:342
myosyn()
Default constructor of the myosyn class. Auto-selects muscle channel when setting up a muscle channel...
Definition: myosyn.cpp:214
void readMuscleTension()
Uses the DAQ subsystem to read the muscle tension detected by the loadcell and puts it in the interna...
Definition: myosyn.cpp:506
void calibrateTension(double loadCellGain=NAN)
Sets the gain to calibrate the transformation of the loadcell voltage to force in newtons....
Definition: myosyn.cpp:468
void setMuscleToneTension(double myMuscleTone_value)
Sets the minimum tension held by the motor of a muscle channel. Corresponds to muscle tone and is the...
Definition: myosyn.cpp:427
void startMuscleControl()
Starts the force controller and update the status of the muscle channel. This function only needs to ...
Definition: myosyn.cpp:589
double encoderAngle2Excursion(double encoderAngle)
Returns the tendon excursion given an encoder angle.
Definition: myosyn.cpp:563
void setMuscleStatus(muscleStatus newStatus)
Function sets the status of the muscle channel object.
Definition: myosyn.cpp:374
void executeControl()
Executes the control law set by the controlRoutine function pointer.
Definition: myosyn.cpp:624
muscleStatus getMuscleStatus()
Returns the status of the muscle channel. The possible statuses are listed in the enum muscleStatus.
Definition: myosyn.cpp:369
double getReferenceTension()
Returns the current reference/target muscle tension that the motor controller is trying to achieve/ma...
Definition: myosyn.cpp:462
void(* stopDAQ)()
Function pointer to the global myosynStop function to stop data acquisition. Only need to call this f...
Definition: myosyn.h:210
double getTendonExcursion()
Returns the current tendon excursion value (in mm) in the internal memory.
Definition: myosyn.cpp:578
double getMuscleTension()
Returns the current muscle tension value (in newtons) in the internal memory.
Definition: myosyn.cpp:520
void(* startDAQ)()
Function pointer to the global myosynStart function to start data acquisition. Only need to call this...
Definition: myosyn.h:204
void windDown()
Function stops/deenergizes the motor of the muscle channel to wind down the tendons before system shu...
Definition: myosyn.cpp:400
void readTendonExcursion()
Uses the DAQ subsystem to read the tendon excursion detected by the shaft encoder and puts it in the ...
Definition: myosyn.cpp:568
void setMaxMuscleTension(double max_tension)
Sets the upper limit to possible muscle tension of the motor of the muscle channel as a protection.
Definition: myosyn.cpp:437
unsigned getChannelID()
Returns the channel ID number of the muscle channel.
Definition: myosyn.cpp:364
void setMotorCommand(double newCommand)
Sets the current motor command to be sent to the DC motor.
Definition: myosyn.cpp:610
void calibrateExcursion(double spoolDiameter=NAN)
Calibrates the rotary incremental shaft encoder to zero degrees and set the conversion from angle to ...
Definition: myosyn.cpp:536
void(* controlRoutine)(unsigned numOutputs, double *outputs, unsigned numInputs, double *inputs)
[FOR FUTURE USE ONLY] Function pointer to any control law you might want the muscle channel to use.
Definition: myosyn.h:341
double getMotorCommand()
Returns the current motor command that is being commanded to the motor.
Definition: myosyn.cpp:605
unsigned myosynNumMuscles()
Returns the number of muscles configured by the library.
Definition: myosyn.cpp:117
unsigned muscle_ld_cell[8][2]
Definition: myosyn.cpp:88
_DAQarrangement
Enumerates the different types of configurations supported by myosyn.
Definition: myosyn.h:23
@ QUADRUPED
Definition: myosyn.h:25
@ RING_OF_FIRE
Definition: myosyn.h:24
@ MUSCLE_MODULE
Definition: myosyn.h:26
unsigned muscle_mtr_en[16][2]
Definition: myosyn.cpp:27
double mtr_trque_calib[16][2]
double myosynSamplingRate(double newSamplingRate=myosyn_samplingRate_global)
Sets the sampling rate of the data acquisition and controller of all the muscle channels....
Definition: myosyn.cpp:136
unsigned muscle_enc_kleo[8][2]
Definition: myosyn.cpp:53
enum _muscleStatus muscleStatus
This ENUM lists the possible statuses of each muscle channel.
DAQarrangement myosynGetConfiguration()
Definition: myosyn.cpp:122
_muscleStatus
This ENUM lists the possible statuses of each muscle channel.
Definition: myosyn.h:33
@ MYOSYN_DISABLED
Definition: myosyn.h:34
@ MYOSYN_CLOSEDLOOP
Definition: myosyn.h:37
@ MYOSYN_ENABLED_WINDUP
Definition: myosyn.h:36
@ MYOSYN_READY_WINDDOWN
Definition: myosyn.h:35
int myosynGetLeaderChannel()
Returns the leader muscle channel which governs/triggers data acquisition on all other muscles.
Definition: myosyn.cpp:181
void myosynStart()
This routine starts the data acquisition on all muscle channels that haven't already been started so ...
Definition: myosyn.cpp:146
double loadcell_calib[8][2]
Definition: myosyn.cpp:97
unsigned muscle_enc_ring[8][2]
Definition: myosyn.cpp:44
void myosynWriteOutputs()
Global function to write all DAQ outputs in a synchronized manner. The results are put into the class...
Definition: myosyn.cpp:203
void myosynWaitForClock()
This blocking function waits for the clock period to finish between two function calls....
Definition: myosyn.cpp:208
unsigned numConfiguredMuscles
Definition: myosyn.cpp:112
void myosynReadInputs()
Global function to read all DAQ inputs in a synchronized manner. The results are put into the class o...
Definition: myosyn.cpp:191
void myosynStop()
This function sops the data acquisition of all muscle channels that were started (ie....
Definition: myosyn.cpp:168
double myosyn_samplingRate_global
Definition: myosyn.cpp:114
enum _DAQarrangement DAQarrangement
Enumerates the different types of configurations supported by myosyn.
unsigned muscle_enc_spl[12][2]
Definition: myosyn.cpp:75
DAQarrangement myosynConfiguration
Definition: myosyn.cpp:111
void myosynSetConfiguration(DAQarrangement DAQconfiguration)
Set the muscle configuration/arrangement type of the library. List of possibilities in the DAQarrange...
Definition: myosyn.cpp:126
int myosynLeader
Definition: myosyn.cpp:113
unsigned muscle_mtr_val[16][2]
Definition: myosyn.cpp:10
unsigned muscle_enc_mtr[12][2]
Definition: myosyn.cpp:62
void myosynSetLeaderChannel(int newLeader)
Sets the leader/master muscle channel which governs/triggers data acquisition on all other muscles.
Definition: myosyn.cpp:186