Broadcasting Actuator_Control Messages to Raspberry Pi 3

asked 2019-09-26 07:10:03 -0600

haloted gravatar image

updated 2019-09-26 07:57:30 -0600

I am relatively new to ROS so bear with me. I am trying to broadcast an array of 4 control inputs with a range between [-1 1] to the actuator_control topic using the actuator_control message under Mavros. On my Raspberry Pi 3 I am running ubuntu mate 16.04 and on my computer I am running ubuntu 16.04 LTS. What I have done so far is setup the ROS network by setting the Master URI to run on my Raspberry Pi 3 and export respective IP addresses in the bashrc file. This is so that my laptop or ground control station is able to see Mavros on the same Wifi network. I have established my laptop can do:

rostopic echo /mavros/imu/data

Without problems meaning the GCS is able to see the node on the raspberry pi 3.

I have a couple of questions: 1. Do I need to create a new ROS package that depends on mavros , mavros_extra, and mavros_msg packages in order to run a python script that will broadcast manufactured actuator commands. Because inside my script I will have

import rospy
from std_msgs.msg import String
# from transmit_thrust.msg import RotorsAction
from transmit_thrust.msg import ThrustAction
from mavros_msgs.msg import ActuatorControl

where mavros_msg is used but was not specified in the catkin_build_pkg <package name=""> depend1 depend2 dependencies. It seems that the script was able to run regardless without throwing the "cannot find module message". I wonder why this is?

  1. It seems actuator_control.msg contains 8 channels with corresponding mixer specifications as detailed in this link. Yet I only needed four channels for my quadrotor control since I would like to transmit directly the actuator levels [-1 1] to each of the four rotors. Does this mean I have to set the other four channels as zeros?

  2. One of my seniors recommended me to use the FMU-bypass mixer to achieve this goal but I am not sure how this works.

The code I am planning to achieve publishing the actuator_control topic is outlined below:

if __name__ == '__main__':
        # configuration
        parser = argparse.ArgumentParser()
        parser.add_argument('-w', '--weight', help='trained weight path', type=str, default='')
        args = parser.parse_args()

        weight_path = args.weight

        if weight_path == "":
            print("Can't find trained weight, please provide a trained weight with --weight switch\n")


            print("Loaded weight from {}\n".format(weight_path))
            model = PPO2.load(weight_path)

         # Needed to load observations here to test this script would be using pickle here
            with open('/home/ted/raisim_workspace/raisimGym/scripts/obArray.pickle', 'rb') as f:
                obs = pickle.load(f)
         # Needed to instantiate an array to save Thrust for publishing         
            Actuator_Control_Message = ActuatorControl()

            # pub = rospy.Publisher('chatter', RotorsAction, queue_size=10)
            pub = rospy.Publisher('/mavros/Actuator_control', Actuator_Control_Message, queue_size=10)
            rospy.init_node('talker', anonymous=True)
            rate = rospy.Rate(100) # 10hz
            while not rospy.is_shutdown():
                for i in range(len(obs)):

                    action, _ = model.predict(obs[i])
                    # print("Action: {}".format(action))

                    Thrust = action2Thrust(action)

                    Actuator_Control_Message.control[0] = action[0][0]
                    Actuator_Control_Message.control[1] = action[0][1]
                    Actuator_Control_Message.control[2] = action[0 ...
edit retag flag offensive close merge delete