11import copy
22import inspect
3+ import logging
34
45import sys
56import time
7+ from pprint import pprint
68
79from rcp .utils .base_device import BaseDevice
810from rcp .utils .communication import ConnectionManager
1113SCALES_COUNT = 4
1214
1315
16+ class DeltaPosError (BaseDevice ):
17+ definition = """
18+ typedef struct {
19+ int32_t delta;
20+ uint32_t oldPosition;
21+ uint32_t position;
22+ int32_t scaledDelta;
23+ int32_t error;
24+ } deltaPosError_t;
25+ """
26+
27+
1428class Servo (BaseDevice ):
1529 definition = """
1630typedef struct {
17- float maxSpeed;
18- float currentSpeed;
19- float jogSpeed;
20- float acceleration;
21- int32_t direction;
22- uint32_t destinationSteps;
23- uint32_t currentSteps;
24- uint32_t desiredSteps;
31+ float maxSpeed;
32+ float currentSpeed;
33+ float jogSpeed;
34+ float acceleration;
35+ int32_t stepsToGo;
36+ uint32_t destinationSteps;
37+ uint32_t previousSteps;
38+ uint32_t currentSteps;
39+ uint32_t desiredSteps;
40+ int32_t currentDirection;
41+ int32_t previousDirection;
42+ GPIO_TypeDef *stepPort;
43+ GPIO_TypeDef *dirPort;
44+ uint16_t stepPin;
45+ uint16_t dirPin;
46+ bool syncEnable;
47+ uint16_t unused;
48+ uint32_t syncScaleIndex;
49+ int32_t syncRatioNum;
50+ int32_t syncRatioDen;
51+ deltaPosError_t syncDeltaPos;
2552} servo_t;
2653"""
2754
2855
2956class Global (BaseDevice ):
3057 definition = """
3158typedef struct {
32- uint32_t executionInterval;
33- uint32_t executionIntervalPrevious;
34- uint32_t executionIntervalCurrent;
35- uint32_t executionCycles;
36- servo_t servo;
37- input_t scales[4];
38- fastData_t fastData;
39- } rampsSharedData_t;
59+ uint32_t executionInterval;
60+ uint32_t executionIntervalPrevious;
61+ uint32_t executionIntervalCurrent;
62+ uint32_t executionCycles;
63+ GPIO_TypeDef *enaPort;
64+ GPIO_TypeDef *usrLedPort;
65+ uint16_t usrLedPin;
66+ uint16_t enaPin;
67+ servo_t servo[1];
68+ input_t scales[5];
69+ fastData_t fastData;
70+ TIM_HandleTypeDef *synchroRefreshTimer;
71+ UART_HandleTypeDef *modbusUart;
72+ deltaPosError_t rampsDeltaPos;
73+ uint16_t servoCycles;
74+ uint16_t servoCyclesCounter;
75+ } rampsHandler_t;
4076"""
4177
4278
4379class Scale (BaseDevice ):
4480 definition = """
4581typedef struct {
46- TIM_HandleTypeDef *timerHandle;
47- int32_t position;
48- int32_t speed;
49- int32_t syncRatioNum, syncRatioDen;
50- uint16_t syncEnable;
51- uint16_t spare;
82+ TIM_HandleTypeDef *timerHandle;
83+ int32_t position;
84+ int32_t speed;
85+ deltaPosError_t scalesDeltaPos;
86+ deltaPosError_t scalesSpeed;
5287} input_t;
5388"""
5489
5590
5691class FastData (BaseDevice ):
5792 definition = """
5893typedef struct {
59- uint32_t servoCurrent;
60- uint32_t servoDesired;
61- uint32_t stepsToGo;
62- float servoSpeed;
63- int32_t scaleCurrent[4];
64- int32_t scaleSpeed[4];
65- uint32_t cycles;
66- uint32_t executionInterval;
67- uint16_t servoEnable;
94+ uint32_t servoCurrent[1];
95+ uint32_t servoDesired[1];
96+ uint32_t stepsToGo[1];
97+ float servoSpeed[1];
98+ int32_t scaleCurrent[5];
99+ int32_t scaleSpeed[5];
100+ uint32_t cycles;
101+ uint32_t executionInterval;
102+ uint16_t servoMode;
103+ uint16_t servoEnable;
68104} fastData_t;
69105"""
70106
@@ -86,33 +122,34 @@ class FastData(BaseDevice):
86122 definition = my_class [1 ].register_type ()
87123 variable_definitions .append (definition )
88124 except Exception as e :
125+ logging .error (e .__str__ ())
89126 failure_list .append (my_class )
90127 unloaded_list = copy .deepcopy (failure_list )
91128 iterations_limit -= 1
92129
93130
94131if __name__ == "__main__" :
95132 from rcp .utils import communication
133+ from loguru import logger as log
96134
97- connection_manager = communication .ConnectionManager ()
135+ connection_manager = communication .ConnectionManager (serial_device = "/dev/ttyUSB1" , baudrate = 115200 , address = 17 , debug = False )
98136 device = Global (connection_manager = connection_manager , base_address = 0 )
99-
100- while True :
101- time .sleep (0.5 )
102- # values = device['fastData'].refresh()
103- # print(
104- # device['executionInterval'],
105- # device['executionIntervalPrevious'],
106- # device['executionIntervalCurrent'],
107- # device['executionCycles']
108- # )
109- values = device ['servo' ].refresh ()
110- print (values )
111-
112- # float maxSpeed;
113- # float currentSpeed;
114- # float acceleration;
115- # int32_t direction;
116- # uint32_t destinationSteps;
117- # uint32_t currentSteps;
118- # uint32_t desiredSteps;
137+ log .info ("Starting test routine for serial modbus communication" )
138+ # while True:
139+ time .sleep (0.5 )
140+ print (f"Ena Port(0x40020800): { device ['enaPort' ]:x} " )
141+ print (f"Ena Pin(1024): { device ['enaPin' ]} " )
142+ print (f"User Led Port(0x40020000): { device ['usrLedPort' ]:x} " )
143+ print (f"User Led Pin(1024): { device ['usrLedPin' ]} " )
144+
145+ print (f"Scale 0 Timer Handle(0x200019d4): { device ['scales' ][0 ]['timerHandle' ]:x} " )
146+ print (f"Scale 1 Timer Handle(0x2000198c): { device ['scales' ][1 ]['timerHandle' ]:x} " )
147+ print (f"Scale 2 Timer Handle(0x20001944): { device ['scales' ][2 ]['timerHandle' ]:x} " )
148+ print (f"Scale 3 Timer Handle(0x200018fc): { device ['scales' ][3 ]['timerHandle' ]:x} " )
149+ print (f"Scale 4 Timer Handle(0x200018b4): { device ['scales' ][4 ]['timerHandle' ]:x} " )
150+
151+ device ['servoCycles' ] = 0
152+ count = 10
153+ while count > 0 :
154+ fastData = device ['fastData' ].refresh ()
155+ pprint (fastData )
0 commit comments