Skip to content

Arduino Mode

Ulysse Vautier edited this page May 19, 2018 · 11 revisions

The Arduino has multiple low-level controller (we call them Modes) depending on the task you want it to have. To change the Mode, the PC has to send a message to the Arduino, asking it to change the mode. To see how the PC asks for the Arduino mode, refer to Making Your Own Controller on the Raspberry Pi. The Arduino will parse the geometry_msgs::Twist message sent by the Raspberry Pi and act upon the actuators depending on the mode chosen. When talking about the mode here, we are using the C++ standard. If you are using Python please change accordingly (i.e. MODE::STANDBY becomes MODE.STANDBY in Python).

Standby Mode

When the arduino starts, it goes directly into standby mode. It does nothing but acquire sensors data and send them to the PC. It will ignore any message coming from the PC.

To send the standby mode message, use MODE::STANDBY.

Rudder-Sail Control Mode

In this mode, the arduino gets the control message from the PC and acts them directly to the rudder and the sail. As such, the control message should contain the input angle of the rudder, and the input angle of the sail.

To send the rudder-sail control mode message, use MODE::RUDDER_SAIL.

The Twist message will be parsed as such :

rudder_angle = message.angular.x
sail_angle = message.angular.y

If the boat has a 2nd rudder, it can be controlled with the z component of the message :

rudder2_angle = message.angular.z

Sail-Heading Control Mode

In this mode, the arduino will put an optimal rudder angle corresponding to the heading. As such, the control message should contain the input angle of the sail, and the vector corresponding to the heading. The heading has to be in the boat reference. Axis Y being in front of the boat and Z axis up.

To send the sail-heading control mode message, use MODE::SAIL_HEADING.

The Twist message will be parsed as such :

sail_angle = message.angular.y
heading = [message.angular.x, message.angular.y]

If the boat has a 2nd rudder, it will have an optimal rudder angle.

Rudder Control Mode

In this mode, the arduino will put an optimal sail angle. As such, the control message should only contain the input angle of the rudder.

To send the rudder control mode message, use MODE::RUDDER.

The Twist message will be parsed as such :

rudder_angle = message.angular.x

If the boat has a 2nd rudder, it can be controlled with the z component of the message :

rudder2_angle = message.angular.z

Heading Control Mode

In this mode, the arduino gets a heading vector/angle from the PC and calculates the optimal rudder and sail angle according to the input heading (and its norm) and wind direction.

To send the heading control mode message, use MODE::HEADING.

A vector can be sent in the twist linear message, or an angle in the angular message. If a vector is sent (non-zero) the angle will be discarded.

The Twist message will be parsed as such :

heading = atan2(message.linear.y, message.linear.x)

or if no vector is sent :

heading = message.angular.z

RC Mode

The RC Mode is a special mode. In this mode, the arduino ignores the PC control messages and only acts according to the Radio Controller Receiver. This mode can be activated by the PC or a Radio Controller itself (with a special combination).

To send the rc mode message, use MODE::RC.

Go Home Mode

The Go Home Mode is a special mode. In this mode, the arduino ignores the PC control messages and acts on its own. It is a security feature in case the PC shuts down. When the sailboat turns on, it keeps a record of the first GPS location it gets. The Go Home Mode sails the boat to this initial GPS location.

The controller base class has an implicit watchdog implemented inside its loop, sending messages every 30 seconds to the Arduino. If the Arduino doesn't receive the message for 5 minutes, it will automatically set its mode to Go Home Mode.

To send the go home mode message, use MODE::RETURN_HOME.