Skip to content

Commit c5c2d6e

Browse files
refactor muscle and node commands and id/port variable names. Update README setup process for Node and Muscle
1 parent dc078aa commit c5c2d6e

32 files changed

+145
-165
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
test-env/
22
asus-venv/
33
asus-venv311/
4+
mtd-venv/
45
venv*
56

67
ThermoflexSessions/

README.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,67 +36,70 @@ pip install --editable .\python-serial\ # OR Install for developement (change
3636

3737
# Launch and Use
3838

39-
Import the thermoflex library and use .discover() to find our product.
39+
Import the thermoflex library and use .discover() to find your Node Controller.
4040

41-
```python
42-
import thermoflex as tf
41+
The `tf.discover()` method searches for USB devices with the Node Controller signature, creating a "NodeNet" object for each one found. A NodeNet represents a network of one or more Node Controllers, where additional devices can be connected via CAN bus to the primary USB-connected node. This allows you to control an entire network of nodes through a single USB connection.
4342

44-
netlist = tf.discover()
45-
network1 = netlist[0]
46-
```
43+
For most users working with a single node, you can simply access the first node in the network:
4744

48-
This will return a list of [NodeNet](#nodenet-commands)-objects. Each [NodeNet](#nodenet-commands) contains a list of [Node](#node-commands)-objects connected at initialization as well as a broadcast [Node](#node-commands) and a self [Node](#node-commands) device. From here you will be able to assign nodes to variables using the .getDevice() command.
49-
50-
``` Python
51-
node0 = network1.node_list[0]
45+
```python
46+
import thermoflex as tf
47+
network = tf.discover()[0] # Find all Node networks over USB and connects to the first one found (0th index)
48+
node0 = network.node_list[0] # Access the first node in the network
5249
```
5350

54-
You can also assign the broadcast node and self node by calling a [NodeNet](#nodenet-commands)'s .broadcast_node and .self_node.
55-
56-
``` Python
57-
node_b = network1.broadcast_node
58-
node_s = network1.self_node
59-
```
51+
For advanced users working with multiple nodes, you have several options:
52+
- Access specific nodes by their position in the network's node list
53+
- Identify nodes by testing messages to determine which node responds
54+
- Each node has a permanent unique ID number accessible using `node.id`. You can identify the Node that you want this way after seeing it respond.
6055

61-
Once you have your connected node bound, you can call its status, reset and logging commands. To use the muscles, you need to create [Muscle](#muscle-commands) objects
56+
Additionally, each NodeNet provides two special Node objects:
57+
- `network.self_node`: Direct access to the node connected via USB
58+
- `network.broadcast_node`: Send commands to all nodes in the network simultaneously
6259

60+
Once you have your connected node bound, you can call its status, reset and logging commands. To use the muscles, you need to create [Muscle](#muscle-commands) objects.
6361

6462

65-
To create [Muscle](#muscle-commands)-class objects, start by calling tf.muscle(). This is where you need input your *idnum*, *resistance*, *length*, and *diameter* values if you have them.
63+
To create [Muscle](#muscle-commands)-class objects, start by calling tf.muscle(). This is where you need input your `portNum` that you want the muscle to connect to (0=M1 and 1=M2 when looking at the phyisical Node Controller port labels)
6664

6765

6866
``` Python
69-
muscle1 = tf.muscle(idnum = 0, resist= 300, diam= 2, length= 150)
70-
muscle2 = tf.muscle(idnum = 1, resist= 290, diam= 2, length= 145)
67+
muscle1 = tf.Muscle(portNum=0, masternode=node0)
68+
muscle2 = tf.Muscle(portNum=1) # You can make an orphaned muscle
7169
```
7270

73-
Note that the *idnum* field is the only field that is neccesary for creating the [Muscle](#muscle-commands)-object.
74-
75-
Next, assign the muscle objects to a node object by calling the .setMuscle() command. This command takes the identification number and the muscle object as arguments
76-
71+
All Muscle objects need to be attached to a Node to operate correctly. This can be done at initialization (like muscle1 above) or by using one of the following methods:
7772
```Python
78-
node0.setMuscle(0, muscle1)
79-
node0.setMuscle(1, muscle2)
73+
node0.attachMuscle(muscle2, 1)
74+
# OR
75+
muscle2.attach(node0, 1)
8076
```
8177

82-
Sessions are automatically created and create a filesystem that exports to a higher level folder. Sessions track the incoming and outgoing serial data and saves it to a .ses file and a .txt file. The .txt files are generated as plain messages, where as the .ses files have serialized messages.
78+
From here, you can send the Node and Muscles commands.
79+
80+
**Command Formats:**
81+
- [Node Commands](#node-commands)
82+
- [Muscle Commands](#muscle-commands)
8383

84+
These commands should be in the format:
8485
```Python
85-
sessionl = tf.Session.sessionl
86-
session1 = session[0]
86+
muscle1.enable() # Muscle command
87+
88+
node0.enable(muscle1) # Node command version (does the same thing)
8789
```
8890

89-
From here, you can add commands to your command buffer. [Node Commands](#node-commands)
91+
Note that for all `Muscle` commands, there exists a similar method in the `Node` object
92+
93+
### Sessions (experimental)
9094

91-
These commands should be in the format,
95+
Our built-in session logging system can create a filesystem that exports to a higher level folder. Sessions track the incoming and outgoing serial data and saves it to a `.ses`, storing Node network and send/received packet information. This data can be analyzed by the `SessionAnalyzer` class. **Note: This feature is experimental. Feel free to create your own logging logic in your scripts.**
9296

9397
```Python
94-
node0.enable(muscle1)
98+
sessionl = tf.Session.sessionl
99+
session1 = session[0]
95100
```
96101

97-
The muscle objects also have their own commands that are passed to their commanding node.[Muscle Commands](#muscle-commands)
98-
99-
Developer install instructions
102+
### Developer install instructions
100103

101104
for testing purposes, use the command
102105
```
@@ -141,7 +144,7 @@ with $SRC being the path to the [python-serial](python-serial/) folder. This wil
141144
| setLogmode(mode) | Sets the logging mode of the node; mode:(0:'none', 1:'compact', 2:'dump', 3:'readable dump') |
142145
| setMode(conmode, device) | Sets the input mode of the node; conmode : (percent, volts, amps, ohms, train); device : (all,node,m1,m2,...,m*n*) |
143146
| setSetpoint(musc, conmode, setpoint) | Sets the point at which the node actuates to; musc: *muscle id number*; conmode : (percent, volts, amps, ohms, train); setpoint : *float* |
144-
| setMuscle(idnum,muscle) | Assigns a muscle to the node; will have presets in the future |
147+
| setMuscle(portNum,muscle) | Assigns a muscle to the node; will have presets in the future |
145148
| enable(muscle) | Enables the selected muscle to act on the value set by setSetpoint(); enable : (*muscle object*) |
146149
| enableAll | Enables all connected muscles of the node |
147150
| disable(muscle) | Disables the selected muscle : (m1,m2,...,m*n*) |

docs/Thermoflex Glossary.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
| setLogmode(mode) | Sets the logging mode of the node; mode:(0:'none', 1:'compact', 2:'dump', 3:'readable dump') |
4747
| setMode(conmode, device) | Sets the input mode of the node; conmode : (percent, volts, amps, ohms, train); device : (all,node,m1,m2,...,m*n*) |
4848
| setSetpoint(musc, conmode, setpoint) | Sets the point at which the node actuates to; musc: *muscle id number*; conmode : (percent, volts, amps, ohms, train); setpoint : *float* |
49-
| setMuscle(idnum,muscle) | Assigns a muscle to the node; will have presets in the future |
49+
| attachMuscle(portNum,muscle) | Assigns a muscle to the node; will have presets in the future |
5050
| enable(muscle) | Enables the selected muscle to act on the value set by setSetpoint(); enable : (*muscle object*) |
5151
| enableAll() | Enables all connected muscles of the node |
5252
| disable(muscle) | Disables the selected muscle : (m1,m2,...,m*n*) |
@@ -60,7 +60,7 @@
6060
| .net | the connected network |
6161
| .arduino | the serial port information and address |
6262
| .logmode | integer logmode for internal use |
63-
| .node_id | the id number of the connected node |
63+
| .id | the id number of the connected node |
6464
| .canid | the id specific to the Can bus of the connected node;seperate from the node id |
6565
| .firmware | the firmware number of the connected node |
6666
| .board_version | the board version of the connected node |
@@ -84,7 +84,7 @@
8484

8585
| **Muscle Attributes** | Purpose |
8686
| --------------------- | ---------------------------------------------------------- |
87-
| .idnum | id number of the muscle connected to the node |
87+
| .portNum | id number of the muscle connected to the node |
8888
| .mosfetnum | number of the mosfet port that the muscle is connected to. |
8989
| .resistance | restance value of the muscle |
9090
| .diameter | diameter of the muscle |

getting-started/identify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
print("Detected Nodes:")
1111
for node in node_net.node_list:
1212
# Print the list of Nodes on the network in X.X.X syntax
13-
print(f'Node: {node.node_id[0]}.{node.node_id[1]}.{node.node_id[2]}')
13+
print(f'Node: {node.id[0]}.{node.id[1]}.{node.id[2]}')
1414

1515
time.sleep(1)
1616
tf.endAll()

getting-started/muscle-simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
node = node_net.node_list[0] # Get the first connected Node
2929

30-
muscle = tf.Muscle(idnum = 0) # Match idnum to the muscle port number 0=M1, 1=M2
31-
node.setMuscle(0, muscle) # Assign the muscle to the Node at port 0
30+
muscle = tf.Muscle(_port = 0) # Match portNum to the muscle port number 0=M1, 1=M2
31+
node.attachMuscle(muscle, 0) # Assign the muscle to the Node at port 0
3232

3333
# Move the Muscle
3434
muscle.setMode("percent")

getting-started/plot-muscle-resist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
node = node_net.node_list[0] # Get the first connected Node
3030

31-
muscle = tf.Muscle(idnum = 0) # Match idnum to the muscle port number 0=M1, 1=M2
32-
node.setMuscle(0, muscle) # Assign the muscle to the Node at port 0
31+
muscle = tf.Muscle(_port = 0) # Match idnum to the muscle port number 0=M1, 1=M2
32+
node.attachMuscle(muscle, 0) # Assign the muscle to the Node at port 0
3333

3434
# Store resistances
3535
resistances = []

python-serial/src/thermoflex.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Install the thermoflex library. You can do this 3 different ways.
4646
3. Download the latest release from [Github Releases](https://github.com/Delta-Robotics-Inc/ThermoFlex-Python-API/releases), cd into the folder and type this command
4747

4848
```bash
49-
pip install thermoflex-1.0.1.tar.gz
49+
pip install thermoflex-1.0.2.tar.gz
5050
```
5151
*The version number is subject to change*
5252

python-serial/src/thermoflex.egg-info/SOURCES.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ src/thermoflex/tools/__init__.py
1616
src/thermoflex/tools/debug.py
1717
src/thermoflex/tools/nodeserial.py
1818
src/thermoflex/tools/packet.py
19-
src/thermoflex/tools/tfnode_messages_pb2.py
20-
src/thermoflex/tools/test/nodetestingscript.py
21-
src/thermoflex/tools/test/testcommands.py
19+
src/thermoflex/tools/tfnode_messages_pb2.py
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

python-serial/src/thermoflex/controls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check_serial_permissions():
4242

4343

4444

45-
def discover(proid = prod):
45+
def discover(proid = prod) -> list[NodeNet]:
4646
'''
4747
4848
Takes node-object idnumber and tries to find corresponding port.

0 commit comments

Comments
 (0)