-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from deepinbubblegum/humble-develop
Humble develop
- Loading branch information
Showing
19 changed files
with
167 additions
and
117 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
moteus_motor/config/params.yaml → moteus_drive/config/params.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
moteus_motor: | ||
moteus_drive: | ||
ros__parameters: | ||
frame_id: "moteus" | ||
rezero_on_startup: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
moteus_drive/moteus_drive/moteus_control/MoteusDrive.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import asyncio | ||
import math | ||
from time import sleep | ||
import moteus | ||
from rclpy.node import Node | ||
|
||
class MoteusDrive(Node): | ||
def __init__(self, IDs): | ||
super().__init__('MoteusDriveCycle') | ||
self.ids = IDs | ||
self.conn = [] | ||
self.state = "stop" | ||
self.terminate = False | ||
self.get_logger().info('MoteusDrive: Initialized') | ||
self.get_logger().info('MoteusDriveState: %s' % self.state) | ||
self.raw_feedback = None | ||
self.rezero = False | ||
self.servo_command = None | ||
self.feedback_position_device = None | ||
|
||
async def run(self): | ||
transport = moteus.Fdcanusb() | ||
for idx, device_id in enumerate(self.ids): | ||
self.conn.append(moteus.Controller(id = device_id)) | ||
while True: | ||
if self.state == "stop": | ||
self.make_stop = [] | ||
for idx, device_id in enumerate(self.ids): | ||
self.make_stop.append(self.conn[idx].make_stop()) | ||
await transport.cycle(self.make_stop) | ||
|
||
if self.rezero: | ||
self.make_rezero = [] | ||
for idx, device_id in enumerate(self.ids): | ||
self.make_rezero.append(self.conn[idx].make_rezero()) | ||
await transport.cycle(self.make_rezero) | ||
self.rezero = False | ||
|
||
while self.terminate is False and self.state == "start" and self.servo_command is not None: | ||
self.make_position = [] | ||
for idx, device_id in enumerate(self.ids): | ||
self.make_position.append( | ||
self.conn[idx].make_position( | ||
position=math.nan, | ||
velocity=self.servo_command[device_id]["velocity"], | ||
maximum_torque=self.servo_command[device_id]["maximum_torque"], | ||
query=True | ||
) | ||
) | ||
self.set_feedback(await transport.cycle(self.make_position)) | ||
await asyncio.sleep(0.01) | ||
await asyncio.sleep(0.01) | ||
|
||
if self.state == "brake" and self.servo_command is not None: | ||
self.make_brake = [] | ||
for idx, device_id in enumerate(self.ids): | ||
self.make_brake.append( | ||
self.conn[idx].make_position( | ||
position = math.nan, | ||
velocity = 0.0, | ||
maximum_torque = self.servo_command[device_id]["maximum_torque"], | ||
stop_position = self.servo_command[device_id]["position"] + self.servo_command[device_id]["velocity"], | ||
query=True | ||
) | ||
) | ||
self.set_feedback(await transport.cycle(self.make_brake)) | ||
# self.state = "stop" | ||
# self.servo_command = None | ||
self.get_logger().info('MoteusDriveState: %s' % self.state) | ||
await asyncio.sleep(0.01) | ||
self.state == "braked" | ||
|
||
def set_feedback(self, feedback): | ||
self.raw_feedback = feedback | ||
|
||
def get_feedback(self): | ||
return self.raw_feedback | ||
|
||
def run_start(self): | ||
asyncio.run(self.run()) | ||
|
||
def set_state_start(self): | ||
self.state = "start" | ||
self.get_logger().info('MoteusDriveState: %s' % self.state) | ||
|
||
def set_state_stop(self): | ||
self.state = "stop" | ||
self.get_logger().info('MoteusDriveState: %s' % self.state) | ||
|
||
def set_state_rezero(self): | ||
self.rezero = True | ||
self.get_logger().info('MoteusDriveRezero: %s' % self.rezero) | ||
|
||
def set_state_terminated(self): | ||
self.set_state_stop() | ||
self.terminate = True | ||
self.get_logger().info('MoteusDriveState: %s' % self.state) | ||
|
||
def set_state_brake(self): | ||
# self.state = "brake" | ||
self.state = "stop" | ||
self.get_logger().info('MoteusDriveState: %s' % self.state) | ||
|
||
def set_state_command(self, command): | ||
self.servo_command = command | ||
if self.state != "start": | ||
self.state = "start" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>moteus_motor</name> | ||
<name>moteus_drive</name> | ||
<version>0.0.1</version> | ||
<description>moteus_motor</description> | ||
<maintainer email="[email protected]">bubble</maintainer> | ||
<license>Apache-2.0</license> | ||
<description>moteus_drive</description> | ||
<maintainer email="[email protected]">chaiwit</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<depend>rclpy</depend> | ||
|
||
|
||
<test_depend>ament_copyright</test_depend> | ||
<test_depend>ament_flake8</test_depend> | ||
<test_depend>ament_pep257</test_depend> | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[develop] | ||
script_dir=$base/lib/moteus_drive | ||
[install] | ||
install_scripts=$base/lib/moteus_drive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
from glob import glob | ||
from setuptools import setup | ||
|
||
package_name = 'moteus_motor' | ||
package_name = 'moteus_drive' | ||
|
||
setup( | ||
name=package_name, | ||
|
@@ -21,12 +21,12 @@ | |
zip_safe=True, | ||
maintainer='bubble', | ||
maintainer_email='[email protected]', | ||
description='moteus_motor', | ||
license='Apache-2.0', | ||
description='moteus_drive', | ||
license='Apache License 2.0', | ||
tests_require=['pytest'], | ||
entry_points={ | ||
'console_scripts': [ | ||
"moteus_motor = moteus_motor.moteus_node:main" | ||
"moteus_drive = moteus_drive.moteus_node:main" | ||
], | ||
}, | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int32 device_id | ||
float64 velocity | ||
float64 maximum_torque |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Header Header | ||
std_msgs/Header header | ||
MoteusCommand[] commands |
Oops, something went wrong.