-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Motors #98
base: develop
Are you sure you want to change the base?
New Motors #98
Changes from 20 commits
3fdd4cb
64c6776
a6e7b1f
8776262
c4a6561
22193df
1743a85
27d7cb1
cc45ea9
f44096e
2543233
55017db
2806cbc
9e3c8be
55a3744
fb9c0c5
7771c1e
1a8eafb
bd89c01
935c236
01237b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import rospy | ||
|
||
from lunabot_msgs.msg import RobotEffort, RobotSensors | ||
from std_msgs.msg import Int8 | ||
from std_msgs.msg import Int8, Int32 | ||
import interrupts | ||
|
||
import time | ||
|
@@ -22,7 +22,7 @@ def __init__(self, excavation_publisher: rospy.Publisher = None, lin_act_publish | |
""" | ||
|
||
if excavation_publisher is None: | ||
self.excavation_publisher = rospy.Publisher("/excavate", Int8, queue_size=1, latch=True) | ||
self.excavation_publisher = rospy.Publisher("/excavate", Int32, queue_size=1, latch=True) | ||
rospy.init_node('plunge_node') | ||
else: | ||
self.excavation_publisher = excavation_publisher | ||
|
@@ -44,7 +44,7 @@ def __init__(self, excavation_publisher: rospy.Publisher = None, lin_act_publish | |
# TODO: check and test this value | ||
self.LOWERING_TIME = 23 #In seconds, how long it takes to lower the linear actuators 90% of the way | ||
|
||
self.EXCAVATION_SPEED = 127 | ||
self.EXCAVATION_SPEED = 1000 #RPM | ||
self.LIN_ACT_SPEED = -110 | ||
|
||
self.is_sim = rospy.get_param("is_sim") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Github won't let me leave a comment in the right place, but two lines down (line 54) exc_message is not updated I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in fix threshold commit |
||
|
@@ -68,7 +68,7 @@ def plunge(self): | |
|
||
time.sleep(0.1) | ||
|
||
excavation_message = Int8() | ||
excavation_message = Int32() | ||
excavation_message.data = self.EXCAVATION_SPEED | ||
|
||
lin_act_message = Int8() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ def stuck(self): | |
error_publisher.publish(stuck_msg) | ||
|
||
# check if trying to go somewhere | ||
if self.robot_effort.left_drive >= 15 or self.robot_effort.right_drive >= 15: | ||
if self.robot_effort.left_drive >= 15 or self.robot_effort.right_drive >= 15: #TODO RJN - these might need to be higher | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're almost certainly correct. That being said, I don't think this file ever gets used. There's a strong argument to be made for deleting it entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in fix threshold commit |
||
# check if not going anywhere | ||
if self.robot_sensors.drive_left_vel <= 0.1 and self.robot_sensors.drive_right_vel <= 0.1: | ||
if not currently_stuck: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import numpy as np | ||
import rospy | ||
from geometry_msgs.msg import Twist | ||
from std_msgs.msg import Int8 | ||
from std_msgs.msg import Int32 | ||
|
||
from lunabot_msgs.msg import RobotSensors | ||
|
||
|
@@ -13,20 +13,16 @@ def __init__(self): | |
# ROS Publishers and subsribers to get / send data | ||
|
||
self._vel_sub = rospy.Subscriber("/cmd_vel", Twist, self._vel_cb) | ||
self._right_drive_pub = rospy.Publisher("/right_drive", Int8, queue_size=1) | ||
self._left_drive_pub = rospy.Publisher("/left_drive", Int8, queue_size=1) | ||
self._right_drive_pub = rospy.Publisher("/right_drive", Int32, queue_size=1) | ||
self._left_drive_pub = rospy.Publisher("/left_drive", Int32, queue_size=1) | ||
self._state_sub = rospy.Subscriber("sensors", RobotSensors, self._robot_state_cb) | ||
|
||
self.width = rospy.get_param("~width", 0.5588) | ||
self.max_speed_percentage = rospy.get_param("~max_speed_percentage", 0.8) | ||
self.hz = rospy.get_param("~hz", 20) | ||
|
||
self._max_speed = rospy.get_param("~max_speed", 2.0) # In rad/s | ||
self.p = rospy.get_param("~p", 3.9) # P gain for PID controller | ||
self.i = rospy.get_param("~i", 0.0) # I gain for PID controller | ||
self.d = rospy.get_param("~d", 0) # D gain for PID controller | ||
self.i_sat = rospy.get_param("~i_saturate", 10) # Max for integral term | ||
|
||
self._max_speed = rospy.get_param("~max_speed", 2.0) * 60 / 2 / np.pi # In rad/s converted to RPM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why this isn't in RPM directly? Also, to convert from linear to angular speed, don't you need wheel diameter (12 inches, if it's relevant) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Max RPM speed is 3000 at full torque and 5000 overall. I see very little downside to capping this at 3000 rpm |
||
|
||
self.lin = 0 | ||
self.ang = 0 | ||
|
||
|
@@ -58,12 +54,8 @@ def _robot_state_cb(self, msg): | |
self._left_vel = msg.drive_left_vel | ||
|
||
def _loop(self): | ||
left_drive_msg = Int8() | ||
right_drive_msg = Int8() | ||
|
||
left_percent_estimate = np.clip(self._left_vel / self._max_speed, -1, 1) | ||
right_percent_estimate = np.clip(self._right_vel / self._max_speed, -1, 1) | ||
|
||
left_drive_msg = Int32() | ||
right_drive_msg = Int32() | ||
|
||
WEIGHT = 0.9 | ||
|
||
|
@@ -73,40 +65,8 @@ def _loop(self): | |
left_set = self.lin - self.ang * self.width / 2 | ||
right_set = self.lin + self.ang * self.width / 2 | ||
|
||
# Measured Velocity in m / s | ||
left_measured = self._left_vel * self._meters_per_rad | ||
right_measured = self._right_vel * self._meters_per_rad | ||
|
||
# Calculating error | ||
left_error = left_set - left_measured | ||
right_error = right_set - right_measured | ||
|
||
self.left_error_sum += left_error | ||
self.right_error_sum += right_error | ||
|
||
self.left_error_sum = np.clip(self.left_error_sum, -self.i_sat, self.i_sat) | ||
self.right_error_sum = np.clip(self.right_error_sum, -self.i_sat, self.i_sat) | ||
|
||
# Calculating motor velocities | ||
left = ( | ||
left_percent_estimate | ||
+ left_error * self.p | ||
+ self.left_error_sum * self.i | ||
+ (left_error - self._left_prev_error) / self.loop_dt * self.d | ||
) | ||
right = ( | ||
right_percent_estimate | ||
+ right_error * self.p | ||
+ self.right_error_sum * self.i | ||
+ (right_error - self._right_prev_error) / self.loop_dt * self.d | ||
) | ||
|
||
# Calculating previous error | ||
self._left_prev_error = left_error | ||
self._right_prev_error = right_error | ||
|
||
left_drive_msg.data = self.constrain(left) | ||
right_drive_msg.data = self.constrain(right) | ||
left_drive_msg.data = self.constrain(left_set * self._meters_per_rad) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This goes and uses the self._meters_per_rad. Due to github, I can't leave a comment directly on that definition, but I think that number may be wrong. Even if it is correct, something more than a magic number would be appreciated. |
||
right_drive_msg.data = self.constrain(right_set * self._meters_per_rad) | ||
|
||
if self.lin == 0 and self.ang == 0: | ||
left_drive_msg.data = 0 | ||
|
@@ -115,12 +75,12 @@ def _loop(self): | |
self._right_drive_pub.publish(right_drive_msg) | ||
|
||
def constrain(self, val): | ||
val = np.clip(-1, val, 1) # Clipping speed to not go over 100% | ||
return np.int8(val * 127 * self.max_speed_percentage) | ||
val = np.clip(-self._max_speed, val, self._max_speed) # Clipping speed to not go over 100% | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah looking at this context self._max_speed should really just be explicity defined as RPM. If needed the paramater is used elsewhere, it would be better to back-calculate it from the rpm value. |
||
return np.int32(val) | ||
|
||
def shutdown_hook(self): | ||
left_drive_msg = Int8() | ||
right_drive_msg = Int8() | ||
left_drive_msg = Int32() | ||
right_drive_msg = Int32() | ||
|
||
left_drive_msg.data = 0 | ||
right_drive_msg.data = 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to this file (and no-sensor-excavate) aren't going to be super important as they will need to be re-written completely. Likely will need to make at least some of these changes again on the new version.