<commit_before># Servode
An ode to Python code that uses Servos ([ROBOTIS](https://github.com/ROBOTIS-GIT/DynamixelSDK) first)

## Usage
### As a library
To connect a Servo and read a register (example: `present_position`):
```python
with ServoProtocol as sp:
    servo = Servo(sp=sp, servo_id=1)
    # to read a value
    value = servo['present_position']
```

To connect a Servo and write a register (example: `goal_position`):
```python
with ServoProtocol as sp:
    servo = Servo(sp=sp, servo_id=1)
    # to read a value
    servo['goal_position'] = 128
```

To connect a group of servos and write values to a register (example: `goal_positiom`):
```python
with ServoProtocol as sp:
    sg = ServoGroup()
    sg['base'] = Servo(sp, stages.arm_servo_ids[0])
    sg['elbow'] = Servo(sp, stages.arm_servo_ids[1])
    sg['wrist'] = Servo(sp, stages.arm_servo_ids[2]),
    sg['claw'] = Servo(sp, stages.arm_servo_ids[3])

   sg.write("goal_position", [
        100,  # first servo value
        200,  # second servo value
        330,  # third servo value
        400   # fourth servo value
    ])
```

### From the command-line
To read a register from one servo:
```
$ ./servode.py read_register --sid 10
2016-11-04 06:01:42,582|servode |INFO: Read register: 'present_position'
2016-11-04 06:01:42,587|servode |INFO: Servo:10 value:497
```
To read a register from two servos:
```
$ ./servode.py read_register --sid 10 --sid 11
2016-11-04 06:01:42,582|servode |INFO: Read register: 'present_position'
2016-11-04 06:01:42,587|servode |INFO: Servo:10 value:497
2016-11-04 06:01:42,589|servode |INFO: Servo:11 value:102
```
To write a value to a register on one servo:
```
$ ./servode.py write_register goal_position 490 --sid 10
2016-11-04 06:23:28,716|servode |INFO: Servo:10 wrote value:490 to register:goal_position
```
To write a value to a register on two servos:
```
$ ./servode.py write_register goal_position 490 --sid 10 --sid 11
2016-11-04 06:24:11,614|servode |INFO: Servo:10 wrote value:490 to register:goal_position
2016-11-04 06:24:11,616|servode |INFO: Servo:11 wrote value:490 to register:goal_position
```
## Installation

1. Download [Servode](https://github.com/lashex/servode/archive/master.zip)
2. unzip Servode
2. Download the latest [ROBOTIS SDK](https://github.com/ROBOTIS-GIT/DynamixelSDK/releases)
3. Change to the directory where `servode.py` resides
4. Un-tar the ROBOTIS SDK:
    ```
    #example
    tar -xvf ~/download/dir/of/DynamixelSDK-#.#.#.tar
    ```  
5. Copy the dynamixel python functions to the directory where `servode.py` resides
    ```
    # example
    cp DynamixelSDK-#.#.#.tar/python/dynamixel_functions_py/dynamixel_functions.py .<commit_msg>updated formatting<commit_after># Servode
An ode to Python code that uses Servos ([ROBOTIS](https://github.com/ROBOTIS-GIT/DynamixelSDK) first)

## Usage
### As a library
To connect a Servo and read a register (example: `present_position`):
```python
with ServoProtocol as sp:
    servo = Servo(sp=sp, servo_id=1)
    # to read a value
    value = servo['present_position']
```

To connect a Servo and write a register (example: `goal_position`):
```python
with ServoProtocol as sp:
    servo = Servo(sp=sp, servo_id=1)
    # to read a value
    servo['goal_position'] = 128
```

To connect a group of servos and write values to a register (example: `goal_positiom`):
```python
with ServoProtocol as sp:
    sg = ServoGroup()
    sg['base'] = Servo(sp, stages.arm_servo_ids[0])
    sg['elbow'] = Servo(sp, stages.arm_servo_ids[1])
    sg['wrist'] = Servo(sp, stages.arm_servo_ids[2]),
    sg['claw'] = Servo(sp, stages.arm_servo_ids[3])

   sg.write("goal_position", [
        100,  # first servo value
        200,  # second servo value
        330,  # third servo value
        400   # fourth servo value
    ])
```

### From the command-line
To read a register from one servo:
```
$ ./servode.py read_register --sid 10
2016-11-04 06:01:42,582|servode |INFO: Read register: 'present_position'
2016-11-04 06:01:42,587|servode |INFO: Servo:10 value:497
```
To read a register from two servos:
```
$ ./servode.py read_register --sid 10 --sid 11
2016-11-04 06:01:42,582|servode |INFO: Read register: 'present_position'
2016-11-04 06:01:42,587|servode |INFO: Servo:10 value:497
2016-11-04 06:01:42,589|servode |INFO: Servo:11 value:102
```
To write a value to a register on one servo:
```
$ ./servode.py write_register goal_position 490 --sid 10
2016-11-04 06:23:28,716|servode |INFO: Servo:10 wrote value:490 to register:goal_position
```
To write a value to a register on two servos:
```
$ ./servode.py write_register goal_position 490 --sid 10 --sid 11
2016-11-04 06:24:11,614|servode |INFO: Servo:10 wrote value:490 to register:goal_position
2016-11-04 06:24:11,616|servode |INFO: Servo:11 wrote value:490 to register:goal_position
```
## Installation

1. Download [Servode](https://github.com/lashex/servode/archive/master.zip)
2. Un-zip Servode
2. Download the latest [ROBOTIS SDK](https://github.com/ROBOTIS-GIT/DynamixelSDK/releases)
3. Change to the directory where `servode.py` resides
4. Un-tar the ROBOTIS SDK:

    ```
    #example
    tar -xvf ~/download/dir/of/DynamixelSDK-#.#.#.tar
    ```  
5. Copy the dynamixel python functions to the directory where `servode.py` resides

    ```
    # example
    cp DynamixelSDK-#.#.#.tar/python/dynamixel_functions_py/dynamixel_functions.py .
{'fraction_non_alphanumeric': 0.13763001485884102, 'fraction_numerical': 0.07838038632986627, 'mean_word_length': 4.0658513640639695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3643965', 'n_tokens_mistral': 2270, 'n_tokens_neox': 1886, 'n_words': 543}