mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-11-08 18:21:15 +00:00
Added status data from rover_drive nodes.
This commit is contained in:
@@ -52,6 +52,7 @@ find_package(catkin REQUIRED COMPONENTS
|
|||||||
FILES
|
FILES
|
||||||
DriveCommandMessage.msg
|
DriveCommandMessage.msg
|
||||||
DriveControlMessage.msg
|
DriveControlMessage.msg
|
||||||
|
DriveStatusMessage.msg
|
||||||
)
|
)
|
||||||
|
|
||||||
## Generate services in the 'srv' folder
|
## Generate services in the 'srv' folder
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
bool first_motor_connected
|
||||||
|
bool second_motor_connected
|
||||||
|
|
||||||
|
float32 first_motor_current
|
||||||
|
float32 second_motor_current
|
||||||
|
|
||||||
|
bool first_motor_fault
|
||||||
|
bool second_motor_fault
|
||||||
|
|
||||||
|
float32 first_motor_temp
|
||||||
|
float32 second_motor_temp
|
||||||
@@ -23,7 +23,7 @@ DEFAULT_RIGHT_BOGIE_TOPIC = "drive_control/right"
|
|||||||
|
|
||||||
UINT16_MAX = 65535
|
UINT16_MAX = 65535
|
||||||
|
|
||||||
DEFAULT_HERTZ = 15
|
DEFAULT_HERTZ = 20
|
||||||
|
|
||||||
WATCHDOG_TIMEOUT = 0.3
|
WATCHDOG_TIMEOUT = 0.3
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import serial.rs485
|
|||||||
import minimalmodbus
|
import minimalmodbus
|
||||||
|
|
||||||
# Custom Imports
|
# Custom Imports
|
||||||
from rover_control.msg import DriveControlMessage
|
from rover_control.msg import DriveControlMessage, DriveStatusMessage
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# Global Variables
|
# Global Variables
|
||||||
@@ -24,6 +24,7 @@ DEFAULT_BAUD = 115200
|
|||||||
DEFAULT_INVERT = False
|
DEFAULT_INVERT = False
|
||||||
|
|
||||||
DEFAULT_DRIVE_CONTROL_TOPIC = "drive_control/rear"
|
DEFAULT_DRIVE_CONTROL_TOPIC = "drive_control/rear"
|
||||||
|
DEFAULT_DRIVE_CONTROL_STATUS_TOPIC = "drive_status/rear"
|
||||||
|
|
||||||
FIRST_MOTOR_ID = 1
|
FIRST_MOTOR_ID = 1
|
||||||
SECOND_MOTOR_ID = 2
|
SECOND_MOTOR_ID = 2
|
||||||
@@ -68,6 +69,8 @@ class DriveControl(object):
|
|||||||
|
|
||||||
self.drive_control_subscriber_topic = rospy.get_param("~drive_control_topic", DEFAULT_DRIVE_CONTROL_TOPIC)
|
self.drive_control_subscriber_topic = rospy.get_param("~drive_control_topic", DEFAULT_DRIVE_CONTROL_TOPIC)
|
||||||
|
|
||||||
|
self.drive_control_status_topic = rospy.get_param("~drive_control_status_topic", DEFAULT_DRIVE_CONTROL_STATUS_TOPIC)
|
||||||
|
|
||||||
self.first_motor = minimalmodbus.Instrument(self.port, FIRST_MOTOR_ID)
|
self.first_motor = minimalmodbus.Instrument(self.port, FIRST_MOTOR_ID)
|
||||||
self.second_motor = minimalmodbus.Instrument(self.port, SECOND_MOTOR_ID)
|
self.second_motor = minimalmodbus.Instrument(self.port, SECOND_MOTOR_ID)
|
||||||
self.__setup_minimalmodbus_for_485()
|
self.__setup_minimalmodbus_for_485()
|
||||||
@@ -75,6 +78,11 @@ class DriveControl(object):
|
|||||||
self.drive_control_subscriber = \
|
self.drive_control_subscriber = \
|
||||||
rospy.Subscriber(self.drive_control_subscriber_topic, DriveControlMessage, self.drive_control_callback)
|
rospy.Subscriber(self.drive_control_subscriber_topic, DriveControlMessage, self.drive_control_callback)
|
||||||
|
|
||||||
|
self.drive_control_status_publisher = rospy.Publisher(self.drive_control_status_topic, DriveStatusMessage, queue_size=1)
|
||||||
|
|
||||||
|
self.drive_control_message = DriveControlMessage()
|
||||||
|
self.new_control_message = False
|
||||||
|
|
||||||
self.run()
|
self.run()
|
||||||
|
|
||||||
def __setup_minimalmodbus_for_485(self):
|
def __setup_minimalmodbus_for_485(self):
|
||||||
@@ -90,9 +98,13 @@ class DriveControl(object):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while not rospy.is_shutdown():
|
while not rospy.is_shutdown():
|
||||||
sleep(0.25)
|
self.send_drive_control_message()
|
||||||
|
self.get_drive_status()
|
||||||
|
sleep(0.005)
|
||||||
|
|
||||||
def drive_control_callback(self, drive_control):
|
def send_drive_control_message(self):
|
||||||
|
if self.new_control_message:
|
||||||
|
drive_control = self.drive_control_message
|
||||||
try:
|
try:
|
||||||
first_motor_register_data = list(MOTOR_DRIVER_DEFAULT_MESSAGE)
|
first_motor_register_data = list(MOTOR_DRIVER_DEFAULT_MESSAGE)
|
||||||
first_direction = \
|
first_direction = \
|
||||||
@@ -111,6 +123,40 @@ class DriveControl(object):
|
|||||||
except Exception, error:
|
except Exception, error:
|
||||||
print "Error occurred:", error
|
print "Error occurred:", error
|
||||||
|
|
||||||
|
self.new_control_message = False
|
||||||
|
|
||||||
|
def get_drive_status(self):
|
||||||
|
status = DriveStatusMessage()
|
||||||
|
|
||||||
|
first_motor_status = [0, 0, 0]
|
||||||
|
second_motor_status = [0, 0, 0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
first_motor_status = self.first_motor.read_registers(3, 3)
|
||||||
|
status.first_motor_connected = True
|
||||||
|
except Exception:
|
||||||
|
status.first_motor_connected = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
second_motor_status = self.second_motor.read_registers(3, 3)
|
||||||
|
status.second_motor_connected = True
|
||||||
|
except Exception:
|
||||||
|
status.second_motor_connected = False
|
||||||
|
|
||||||
|
if status.first_motor_connected:
|
||||||
|
status.first_motor_current = first_motor_status[0] / 1000.0
|
||||||
|
status.first_motor_fault = first_motor_status[1]
|
||||||
|
status.first_motor_temp = first_motor_status[2] / 1000.0
|
||||||
|
|
||||||
|
if status.second_motor_connected:
|
||||||
|
status.second_motor_current = second_motor_status[0] / 1000.0
|
||||||
|
status.second_motor_fault = second_motor_status[1]
|
||||||
|
status.second_motor_temp = second_motor_status[2] / 1000.0
|
||||||
|
|
||||||
|
def drive_control_callback(self, drive_control):
|
||||||
|
self.drive_control_message = drive_control
|
||||||
|
self.new_control_message = True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
DriveControl()
|
DriveControl()
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<group ns="sender_transports">
|
<group ns="sender_transports">
|
||||||
<arg name="target" default="192.168.1.10" />
|
<arg name="target" default="192.168.1.10" />
|
||||||
|
|
||||||
<node name="udp_sender4" pkg="nimbro_topic_transport" type="udp_sender" output="screen">
|
<node name="ground_staion_drive_udp_sender" pkg="nimbro_topic_transport" type="udp_sender" output="screen">
|
||||||
<param name="destination_addr" value="$(arg target)" />
|
<param name="destination_addr" value="$(arg target)" />
|
||||||
<param name="destination_port" value="17020" />
|
<param name="destination_port" value="17020" />
|
||||||
<rosparam param="topics">
|
<rosparam param="topics">
|
||||||
|
|||||||
Reference in New Issue
Block a user