Basic threaded RMP interface example

RMP 210, 220, 440LE, 440SE, 440 Omni
Post Reply
User avatar
phussey
Posts: 79
Joined: Fri Apr 20, 2012 8:12 am
Contact:

Basic threaded RMP interface example

Post by phussey » Tue Dec 17, 2013 11:54 am

This is intended to serve as a basic example on how to interface with the RMP platform via ethernet.

The files to modify for your own application would be:

EXAMPLE_MAIN.py: the main application that shows how to start the RMP thread, communicate with it and handle the events
user_event_handlers.py: defines what to do with the signals from the RMP communication thread
rmp_config_params.py: define the user configurable parameters that are loaded and verified at start

The example does the following:
1. Creates an RMP ethernet UDP communication thread
3. Checks configuration against user configuration in rmp_config_params.py
4. Loads and mismatched parameters and verifies them
5. Puts the platform in tractor mode
6. Cycles through all the audio commands while commanding zero motion in between
7. Puts the platform in standby mode
8. Collects all feedback while running, logs it, and prints just the inertial data
8. Kills the thread and the main loop

This example should give a user all of the necessary methods for creating their own event handlers and main applications.
BASIC_RMP_INTERFACE_EXAMPLE.zip
You do not have the required permissions to view the files attached to this post.
PATRICK HUSSEY
Principal Engineer

STANLEY INNOVATION, INC
www.stanleyinnovation.com

muhdsadiquep
Posts: 4
Joined: Wed Apr 26, 2017 6:19 am
Contact:

How to run the Basic Threaded RMP interface example

Post by muhdsadiquep » Tue May 30, 2017 3:02 am

Hello,

Could anyone explain how to run this program ? Is it compatible with Microsoft Visual Studio?

Hoping reply soon.

Regards,
Muhammed Sadique

bradysack
Posts: 2
Joined: Mon Dec 04, 2017 6:07 pm
Contact:

Threaded Example USB connection

Post by bradysack » Mon Aug 06, 2018 11:40 am

Hello Patrick!

I'm attempting to use the threaded interface example with USB connection, but am running into difficulty. Using the IO_USB_CMD.py file from the Demo OCU and the IO_ETH_CMD.py from the threaded example as examples, I tried to write my own USB cmd file for the threaded interface example:

Code: Select all

from utils import convert_byte_data_to_U32, convert_float_to_u32
from system_defines import *
import socket, serial, time, glob, fnmatch, sys

class IO_USB:
    def __init__(self):
	
	self.success = True;
        
        """
        Initialize the flag, find all rmp device ports, and initialize the
        baud rate.
        """
        self.init_failed = False;
        self.baud_rate = 115200;
        if (False == self.find_rmp_device_ports()):
	    print("False")
            self.init_failed = True;
	    self.success = False;
        
        """
        Initialize link status counters
        """
       
        self.dropped_packet = 0;
        self.prev_cmd_time = 0.0;
        self.recieved_items = 0;

    def Send(self,data):
        #try:
	  print(data)
          self.conn.write(data)      
        #except:
          #pass
    
    def Receive(self,num_of_return):
        
        """
        The number of bytes expected is the number of 32-bit messages times
        the bytes per 32-bit word
        """    
        num_of_bytes = num_of_return * 4
        
        """
        Try receiving the data up to a maximum size. If it fails
        empty the data
        """
        try:
            data = self.conn.recv(1024)
        except:
            data = []
            
        """
        If the data is the length expected, convert the byte data to U32 data and return it.
        Otherwise return the None type.
        """
        if (len(data) == num_of_bytes):
            return_data = convert_byte_data_to_U32(data);
        else:
            return_data = None; 
            
        return return_data;

    def Close(self):
        self.conn.close()
	
    def find_rmp_device_ports(self,preferred_list=['*']):
  
	dummy_command = [RMP_CFG_CMD_ID,RMP_CMD_NONE,0]
        port_discovered = False;
        if (False == port_discovered):
        	#try:
            		self.conn = serial.Serial('/dev/ttyACM0', baudrate=self.baud_rate,timeout = .015,writeTimeout = 0.015);
                	self.conn.flushInput()
			self.Send(self.Convert_RMP_Cmds_for_Serial_Interface(dummy_command))
			print(self.conn.readable())
                	data = self.conn.read(1024);
			print(self.conn.read(1))
                	if (len(data) != 0):
				print("yaaay")
                		port_discovered = True;
                	        self.comm_port = ports[i]
                	        self.conn.flushInput()
               		else:
				print("nope")
                	        #self.conn.open()
				
                    
	return port_discovered
	
	
    def Convert_RMP_Cmds_for_Serial_Interface(self,input_cmds):
        	"""
        	Convert a set of commands for the UDP Ethernet interface
        	"""
        	rmp_cmd = [0]*NUM_USB_ETH_BYTES;
		cmds = [0]*3
		
		cmds[0] = input_cmds[0]
		cmds[1] = int(convert_float_to_u32(input_cmds[1]))
                cmds[2] = int(convert_float_to_u32(input_cmds[2]))
        	
        	rmp_cmd[RMP_USB_ETH_CAN_ID_HIGH_INDEX] = int((cmds[0] & 0xFF00) >> 8)
        	rmp_cmd[RMP_USB_ETH_CAN_ID_LOW_INDEX]  = int((cmds[0] & 0x00FF))
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_0_INDEX]  = int((cmds[1] & 0xFF000000) >> 24)
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_1_INDEX]  = int((cmds[1] & 0x00FF0000) >> 16)
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_2_INDEX]  = int((cmds[1] & 0x0000FF00) >> 8)
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_3_INDEX]  = int((cmds[1] & 0x000000FF))
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_4_INDEX]  = int((cmds[2] & 0xFF000000) >> 24)
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_5_INDEX]  = int((cmds[2] & 0x00FF0000) >> 16)
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_6_INDEX]  = int((cmds[2] & 0x0000FF00) >> 8)
        	rmp_cmd[RMP_USB_ETH_CAN_DATA_7_INDEX]  = int((cmds[2] & 0x000000FF))
        	
        	"""
        	Convert the string to char data and return it
        	"""
        	rmp_cmd_chars = []
        	for x in range(0,len(rmp_cmd)):
        	    rmp_cmd_chars.append(chr(rmp_cmd[x]))   
        	
        	output = ''.join(rmp_cmd_chars)
		
        	
        	return output        
        
        
I've imported the convert functions from utils and copy and pasted the Convert_RMP_Cmds_for_Serial_Interface and find_rmp_device_ports methods from the Demo OCU python scripts. I decided to hardcode the port name to simplify the code. I added several print statements as well to troubleshoot my issues. Lastly, I commented out the try and excepts so that the terminal would throw errors that I could read. It seems that, while I can send the dummy command to the port, the pyserial read() function does not read anything off the port. My suspicion is that the dummy command, which is supposed to elicit a response from the RMP, is the wrong command to send in this new threaded version of the software.

Anyway, when I run the example_main.py file with the RMP connected via usb (into the hardcoded usb port), the find_rmp_device_ports function returns port_discovered = false and the program kills itself. It is, however, able to create the serial.Serial instance and write to the port. Do you see any mistakes in my code or able to help me in anyway?

Looking at the preview, it seems the formatting of the find_rmp_device_ports was messed up (the code formatting thing on the forum probably doesn't agree with my indentations :D ), so I'll attach a screenshot of the method as well.

Please let me know if you need any more information!

Thank you!
Brady

I am using an RMP_440_LE Segway and Ubuntu Linux 16.04 to code. I'm using Gedit to edit the scripts.
You do not have the required permissions to view the files attached to this post.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest