Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5aa6f7a
pushing empty files
Yug-Vashisth Mar 18, 2025
ccbd752
added ritiviks code for reference... can start making changes now
Yug-Vashisth Mar 18, 2025
06a4d5f
started making changes... created the function, have to change main n…
Yug-Vashisth Mar 18, 2025
06db1f5
made simple change, took out function call to modbus_init, and change…
Yug-Vashisth Mar 18, 2025
4a393f4
Add motor class for better encapsulation of motor functions
luisss3 Mar 19, 2025
53b1260
add gtest, not tested with hardware yet
luisss3 Mar 19, 2025
67b1c4c
Merge branch 'motor_api' of https://github.com/luisss3/Exoskeleton-Em…
luisss3 Mar 19, 2025
1e6e8d2
Add get actual torque function
luisss3 Mar 30, 2025
57e0d8f
get actual Speed function added
luisss3 Mar 30, 2025
ddbea3e
add position control functions, read write 32int_t functions
luisss3 Mar 30, 2025
18c750c
clean up api and header files
luisss3 Mar 30, 2025
5ac7223
Update README.md
luisss3 Mar 30, 2025
a53cc94
update cmakelist
luisss3 Mar 30, 2025
6792348
Add actual current read function
luisss3 Apr 4, 2025
c22365b
Fixed semantic bugs in motor API
deshpr3 Apr 5, 2025
b6446f8
Merge pull request #1 from deshpr3/motor_api_patch
luisss3 Apr 7, 2025
6f756d1
motor api tests torque and reads back actual value
luisss3 Apr 13, 2025
c5224d9
Merge branch 'motor_api' of https://github.com/luisss3/Exoskeleton-Em…
luisss3 Apr 13, 2025
d1f20b1
motor api merge errors
luisss3 Apr 13, 2025
e17a79b
Merge remote-tracking branch 'remotes/origin/motor_api'
luisss3 Apr 28, 2025
bb84072
Merge /sensors/ from sensor-feature branch
luisss3 Apr 28, 2025
f4c1c7f
multiple motors at the same time can be run
luisss3 Apr 29, 2025
4f4d14d
Merge branch 'McMasterExoskeleton:main' into motor_api
luisss3 May 1, 2025
7541169
Add temperature reading and error clearing functionality
luisss3 May 14, 2025
5cf9ff3
remove duplicate definition
luisss3 May 14, 2025
a19d67e
Merge branch 'motor_api' of https://github.com/luisss3/Exoskeleton-Em…
luisss3 May 14, 2025
866e5b9
Merge pull request #2 from McMasterExoskeleton/main
luisss3 May 14, 2025
29299b8
Update gitignore
luisss3 May 14, 2025
fec9236
Merge branch 'motor_api' of https://github.com/luisss3/Exoskeleton-Em…
luisss3 May 14, 2025
5960840
remove untracked files
luisss3 May 14, 2025
dcaf828
Delete sensors/filtered_differences.txt
luisss3 May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 51 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,62 @@
# Prerequisites
*.d
# ------------------------------------------------------------------------------
# Build artifacts
# ------------------------------------------------------------------------------

# Compiled Object files
*.slo
*.lo
# CMake build directory
build/
CMakeFiles/
CMakeCache.txt
cmake_install.cmake
Makefile

# Object and output files
*.o
*.obj
*.so
*.a
*.dll
*.dylib
*.lib
*.out
*.exe
*.app
*.slo
*.lo
*.lai
*.la

# Precompiled Headers
# Precompiled headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
# Fortran modules
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Dependency files
*.d

# Executables
*.exe
*.out
*.app
# ------------------------------------------------------------------------------
# IDE and Editor files
# ------------------------------------------------------------------------------

# VSCode
.vscode/
*.code-workspace

# JetBrains IDEs (CLion, etc.)
.idea/

# Vim
*.swp
*.swo

# Emacs
*~

# ------------------------------------------------------------------------------
# System files
# ------------------------------------------------------------------------------

.DS_Store
Thumbs.db
36 changes: 25 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
cmake_minimum_required(VERSION 3.14)
project(MyProject)
project(ExoskeletonFirmware)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Add source files
# add_library(MyLibrary src/my_library.cpp)
# Enable testing
enable_testing()

# Include GoogleTest
# Add googletest
add_subdirectory(googletest)

# Enable testing
enable_testing()
# Motor API library
add_library(motor_api
motors/motor_api.cpp
)
target_include_directories(motor_api PUBLIC motors)
target_link_libraries(motor_api PRIVATE modbus)

# Add test for motor API
add_executable(motor_api_test
tests/motor_api_test.cpp
)

target_include_directories(motor_api_test PRIVATE motors)
target_link_libraries(motor_api_test
motor_api
gtest
gtest_main
)

# Add unit tests
add_executable(sampleTest tests/sample_test.cpp)
target_link_libraries(sampleTest PRIVATE gtest gtest_main)
add_test(NAME MotorAPITest COMMAND motor_api_test)

# Register the test with CTest
add_test(NAME sampleTest COMMAND sampleTest)
# add more components later (sensors, control, etc.)
90 changes: 88 additions & 2 deletions motors/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,88 @@
# Motor Control
Submodule of McMaster exoskeleton interfacing and controlling suit motors
# MotorAPI – High-Level Modbus RTU Motor Control

This C++ library provides a high-level interface to control motors via Modbus RTU using [`libmodbus`](https://libmodbus.org/). It abstracts low-level register operations into simple function calls like `setSpeed()`, `setTorque()`, and `getActualPosition()`.

## Features

- Connects to motor over Modbus RTU via serial
- Set motor torque, velocity, and position
- Read actual motor torque, velocity, and position
- Set operation modes (position, velocity, torque)
- Includes safety checks and debug logging
- GTest-compatible for unit testing #TODO

## Dependencies

- [libmodbus](https://libmodbus.org/)
- C++17 or later
- GoogleTest (optional for testing)

## Usage

### Initialization

<pre><code class="language-cpp">
Motor motor("/dev/ttyUSB0", 1);
if (!motor.initializeMotor()) {
std::cerr &lt;&lt; "Failed to connect to motor.\n";
}
</code></pre>

### Set Operation Mode

<pre><code class="language-cpp">
motor.setOperationMode(PV_MODE); // PV_MODE, PT_MODE, or PP_MODE
</code></pre>

### Control Commands

<pre><code class="language-cpp">
motor.setTargetVelocity(1000); // in INC/s
motor.setTorque(500); // in ‰ (permille)
motor.setPosition(100000); // in INC
</code></pre>

### Read Feedback

<pre><code class="language-cpp">
int32_t pos = motor.getActualPosition();
int32_t speed = motor.getActualVelocity();
int16_t torque = motor.getActualTorque();
</code></pre>

### Cleanup

<pre><code class="language-cpp">
motor.stopMotor();
motor.disconnectMotor();
</code></pre>

## Running Tests (Optional)

If hardware is connected and available:

```bash
mkdir build && cd build
cmake ..
make
./motor_api_test
```

## Notes

- `setTorque()` enforces bounds between -3000‰ and +3000‰.
- `setMaxTorque()` only allows values up to 3000‰.
- All `read*()` functions return zero if a read fails, and error messages are printed to `stderr`.
- The motor must be placed in the correct operation mode (`PP_MODE`, `PV_MODE`, `PT_MODE`) before calling `setPosition()`, `setTargetVelocity()`, or `setTorque()`.
- This API assumes motors follow the Modbus RTU protocol and register map of the EZmotion PRS/SRS R2 series.
- Always verify that your power supply voltage and current limits match the motor specifications.
- Communication defaults:
- Baud rate: `115200`
- Parity: Even (`'E'`)
- Data bits: 8
- Stop bits: 1

## Reference

This API is designed based on the **PRS SRS R2 Series User Guide** documentation.
Refer to **Section 6: Register Table** in the official User Guide for detailed register definitions and explanations.
Loading
Loading