Example #1
0
    def connect_driver(self, request):
        if self.driver:
            return (False, "Already connected.")

        self.driver = ODriveInterfaceAPI(logger=ROSLogger())
        rospy.loginfo("Connecting to ODrive...")
        if not self.driver.connect(odrive_id=self.od_id):  #"336431503536"
            self.driver = None
            #rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")

        rospy.loginfo("ODrive connected.")

        # okay, connected,
        #self.m_s_to_value = self.driver.encoder_cpr/self.tyre_circumference - - Dale removed

        #self.driver.axis0.encoder.shadow_count -- is actual position - 1. So on powerup it is -1
        #pos_cpr is just position within one rotation. So not work for you with geared motor
        if self.publish_odom:
            self.old_pos_l = self.driver.axis0.encoder.pos_cpr
            self.old_pos_r = self.driver.axis1.encoder.pos_cpr

        self.fast_timer_comms_active = True

        return (True, "ODrive connected successfully")
Example #2
0
    def connect_driver(self, request):
        if self.driver:
            return (False, "Already connected.")

        if self.sim_mode:
            ODriveClass = ODriveInterfaceSimulator
            self.driver = ODriveInterfaceSimulator(logger=ROSLogger())
        else:
            ODriveClass = ODriveInterfaceAPI
            self.driver = ODriveInterfaceAPI(logger=ROSLogger())

        rospy.loginfo("Connecting to ODrive...")
        if not self.driver.connect(right_axis=self.axis_for_right):
            self.driver = None
            #rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")

        #rospy.loginfo("ODrive connected.")

        # okay, connected,
        self.m_s_to_value = self.driver.encoder_cpr / self.tyre_circumference

        if self.publish_odom:
            self.old_pos_l = self.driver.left_axis.encoder.pos_cpr
            self.old_pos_r = self.driver.right_axis.encoder.pos_cpr

        self.fast_timer_comms_active = True

        self.status = "connected"
        self.status_pub.publish(self.status)
        return (True, "ODrive connected successfully")
Example #3
0
    def connect_driver(self, request):
        # Edit by GGC on June 14: 
        # Checks if driver is connected.  If it is, returns False and says so
        # Initializes driver log
        # Calls connect() function and passes it what right_axis is
        # If it fails to connect, sets driver to None again and returns False
        # Calculates conversion from m/s input to count value
        # Initializes positions of left and right axes (motors)
        # Starts Fast Timer Communications
        # If all goes well, returns True and reports that the ODrive connected

        if self.driver:
            return (False, "Already connected.")
        
        self.driver = ODriveInterfaceAPI(logger=ROSLogger())
        rospy.logwarn("Connecting to ODrive...")
        if not self.driver.connect(right_axis=self.axis_for_right,snum=self.serial_number):   #port=self.port_nunber
            self.driver = None
            #rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")
            
        #rospy.loginfo("ODrive connected.")
        
        # okay, connected, 
        self.m_s_to_value = self.driver.encoder_cpr/self.tyre_circumference
        
        if self.publish_odom:
            self.old_pos_l = self.driver.left_axis.encoder.pos_cpr
            self.old_pos_r = self.driver.right_axis.encoder.pos_cpr
        
        self.fast_timer_comms_active = True
        
        return (True, "ODrive connected successfully")
Example #4
0
    def connect_driver(self, request):
        if self.driver:
            rospy.logerr("Already connected.")
            return (False, "Already connected.")

        self.driver = ODriveInterfaceAPI(calibrate_axis=self.Calibrate_Axis,
                                         USER_CPR=self.user_cpr,
                                         drive_mode=self.drive_mode,
                                         logger=ROSLogger())
        rospy.loginfo("Connecting to ODrive...")
        if not self.driver.connect(right_axis=self.axis_for_right):
            self.driver = False
            rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")

        rospy.loginfo("ODrive connected.")

        self.m_s_to_value = self.driver.encoder_cpr / self.tyre_circumference

        if self.publish_odom:
            if self.Calibrate_Axis != 1:
                self.old_pos_l = self.driver.left_axis.encoder.pos_cpr
            else:
                self.old_pos_r = self.driver.right_axis.encoder.pos_cpr

        return (True, "ODrive connected successfully")
Example #5
0
 def connect_driver(self, request):
     if self.driver:
         rospy.logerr("Already connected.")
         return (False, "Already connected.")
     
     self.driver = ODriveInterfaceAPI(logger=ROSLogger())
     rospy.loginfo("Connecting to ODrive...")
     if not self.driver.connect(right_axis=self.axis_for_right):
         self.driver = False
         rospy.logerr("Failed to connect.")
         return (False, "Failed to connect.")
         
     rospy.loginfo("ODrive connected.")
     
     self.m_s_to_value = self.driver.encoder_cpr/self.tyre_circumference
             
     
     return (True, "ODrive connected successfully")
Example #6
0
    def connect_driver(self, request):
        if self.driver:
            return (False, "Already connected.")

        self.driver = ODriveInterfaceAPI(logger=ROSLogger())
        rospy.loginfo("Connecting to ODrive...")
        if not self.driver.connect(right_axis=self.axis_for_right,
                                   odrive_id=self.od_id):
            self.driver = None
            #rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")

        rospy.loginfo("ODrive %s connected." % self.driver.id)
        self.start_time = rospy.get_time()

        # okay, connected,

        return (True, "ODrive connected successfully")
Example #7
0
    def connect_driver(self, request):
        if self.driver:
            return (False, "Already connected.")

        ODriveClass = ODriveInterfaceAPI if not self.sim_mode else ODriveInterfaceSimulator

        self.driver = ODriveInterfaceAPI(logger=ROSLogger())
        rospy.loginfo("Connecting to ODrive...")
        if not self.driver.connect(tilt_axis=self.axis_for_tilt):
            self.driver = None
            #rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")

        #rospy.loginfo("ODrive connected.")

        # okay, connected,
        self.fast_timer_comms_active = True

        self.status = "connected"
        self.status_pub.publish(self.status)
        return (True, "ODrive connected successfully")
Example #8
0
    def connect_driver(self, request):
        if self.driver:
            rospy.logerr("Already connected.")
            return (False, "Already connected.")

        #create the driver object which is the ODrive Interface API
        self.driver = ODriveInterfaceAPI(logger=ROSLogger())
        rospy.loginfo("Connecting to ODrive...")
        if not self.driver.connect(right_axis=self.axis_for_right):
            self.driver = False
            rospy.logerr("Failed to connect.")
            return (False, "Failed to connect.")

        rospy.loginfo("ODrive connected.")

        self.m_s_to_value = self.driver.encoder_cpr / self.tyre_circumference

        if self.publish_odom:
            self.old_pos_l = self.driver.left_axis.encoder.pos_cpr
            self.old_pos_r = self.driver.right_axis.encoder.pos_cpr

        return (True, "ODrive connected successfully")
Example #9
0
import traceback

import odrive
from odrive.enums import *
from odrive.utils import dump_errors
import pdb

ods = []

count = 3

#ids = ["206A3398304B","2069339E304B", "2069339B304B"]
ids = [None, None]

for i in ids:
    od = ODriveInterfaceAPI()
    od.connect(odrive_id=i)
    pdb.set_trace()
    od.engage()
    ods.append(od)

start_time = time.time()
cycle_count = 0
while True:
    cycle_count += 1
    print("Odrive is running at %i hz" % (cycle_count /
                                          (time.time() - start_time)))
    for od in ods:
        od.drive_pos(10, 10, None)
        h = od.driver.axis0.encoder.pos_cpr
        h = od.driver.axis1.encoder.pos_cpr