Modify thrusters to respond to bytes sent over I2C channel

Greetings OpenROV enthusiasts,

I’m working a thesis that involves modifying the OpenROV Arduino software (openrov-software-arduino directory) so that the thrusters on the OpenROV 2.8 adjusts their speeds and directions autonomously using bytes read over an I2C channel.

I’ve been successful in reading and writing bytes between the OpenROV 2.8 and an Arduino Mega 2560 microcontroller utilizing the I2C channel. The only issue is that I don’t have a method to successfully re-adjust the speeds and directions of the thrusters continuously with the bytes sent from the Arduino Mega. I’ve tried modifying the “CThrusters_2X1.cpp” with “if” statements and while loops, but the thrusters never start, and a while loop seems to make the thrusters crash. I know that the bytes are being successfully read continuously from the Arduino Mega and the bytes being sent are the correct values to run the thrusters.

I’d really appreciate assistance with figuring out how to modify the OpenROV Arduino software so that the thrusters re-adjust their speeds and directions autonomously according to the OpenROV I2C channel and not the buttons on a keyboard. Feel free to ask me questions.

Sincerely,
Cameron Whitaker

There is quite a bit of history with I2C issues during OpenROV 2.6 -2.8 development. You might try a site search with “I2C” and “IMU” to access many of these threads. As I recall, the bottom line is that I2C issues for external sensors were not fully resolved and shared by the OpenROV development team, before moving on to Trident. Others, however, may have since addressed this with newer approaches.
Good luck with your project.

Thank you for your response Howard! I appreciate that you took the time to give me a solution. However, I should have been more specific that the issue is not with the I2C library, it’s with the thrusters.

I’ve been trying to figure out why a thruster won’t spin when, for example, “vertical_motor.SetMotorTarget( new_v )”, within the “CThrusters_2X1.cpp” file is run with the correct PWM values continuously and with none of keyboard buttons pressed, but the thruster doesn’t spin at all. The only way I’ve been successful in getting a thruster to change its speed based on values that are not passed in with command.m_arguments[1] is by using the following if condition:

if( command.Equals( "lift" )) 
{
            uint8_t thruster_speed = 231;
            trg_lift = thruster_speed / 100.0;
            //v = 1500 + 500 * trg_lift; 

            if( m_readTimer.HasElapsed( 400 ) )
            {

                uint8_t thruster_speed = 0;
                trg_lift = thruster_speed / 100.0;
                //v = 1500 + 500 * trg_lift;
            }
            v = 1500 + 500 * trg_lift;
}

The only drawback is that I have to either tap or press a keyboard button for the thruster to switch between speeds. I’ve been analyzing “CCommand.cpp” to try and figure out what information is passed from the Beaglebone Black and the piloting Arduino when the keyboard buttons for the vertical motor are pressed. No answer has occurred.

I know that CCommand& command is a databuffer. I’ve determined that that if( command.Equals( “lift” )) is only called once while a keyboard button for the thruster is pressed once again when the keyboard button is released.

What could be the hidden information contained within CCommand& command that makes “int CMotor::SetMotorTarget( int targetIn_us )” loop and run the thruster? Could the solution be to edit “int CMotor::SetMotorTarget( int targetIn_us )” in “CMotor.cpp” with a different looping method?