Programming Tasks

Algorithms – Write, Code, Flowchart, Draw, etc. for Basic Maneuvers, then combine to do more complicated tasks in Project

Develop algorithm and code for 3 sailing challenges and demonstrate them with your boat.

Choose from these tasks:

1. Beating-upwind course –

Starting behind a “line”, sail upwind to cross another line approx. 30m upwind.

Finish position should be with +-15 meters side to side

2. Run-downwind course –

Starting behind a “line”, sail downwind to cross another line approx. 30m upwind. Include at least 1 jibe

Finish position should be with +-15 meters side to side

3. Station keeping course –

Boats will sail into a 20 m x 20 m "box" formed by four buoys with known GPS locations.

The boats should to remain in the box for a given amount of time, then exit the box.

4. Sail at compass angle

Sail at a given heading from a starting point. Given heading will not be in the no-go range. Make one course change to another given angle (no tack or jibe required)

5. Sail to WayPoint

Sail to within 3 meters of a waypoint from a given starting position that is approximately 20 meters away

6. Get out of Irons

Sail into irons, wait for 10 seconds or so, then get out of irons and sail away on a port tack

-----------------------------------------------------------------------------------------------------------------------

Starter code:

Write/describe the commands you would send to the rudder servo motor and the sail winch servo motor. (you can start with manual rudder if you like)

Sail at close-hauled or any other angle

Given: Wind angle to sail, Close Haul = 45°

1. Get Relative Wind angle and compare to desired angle

2. Compare to desired angle in a set of “if” statements for ranges of relative wind values.

3. Calculate desired rudder and sail angles for each cases

4. Command Motors to specified positions

5. Go back to step 1

6. Consider holding rudder in slightly to counter rounding up due to heel (rudderCMD) sign(RelWind)*20

Sail at compass angle

Given: Direction to sail from a compass (could be from a compass or from a waypoint calculation)

need to turn rudder and have sail adjust appropriately for wind

1. Get Compass heading and RelativeWindDirection

2. Calculate heading change needed RelAngletoWP = AbsAngletoWP - Compass

3. Compare angles in a set of “if” statements for ranges of relative wind values.

4. Calculate desired rudder for each case.

5. Sail follows wind direction

6. Command Motors to specified positions

7. Go back to step 1

8. Think about how to stay on desired angle – will drift off

Sail to WayPoint

Given: GPS location of destination, GPS of current boat position

1. Get GPS location, Compass heading and RelativeWindDirection

2. Calculate heading change needed RelAngletoWP = AbsAngletoWP - Compass

3. Compare angles in a set of “if” statements for ranges of relative wind values.

4. Calculate desired rudder for each case.

5. Sail follows wind direction

6. Command Motors to specified positions

7. Check distance from location – if too big Go back to step 1

else return and get position of next waypoint

Get out of Irons

Need to back out of irons and get in to position where you can sail off in close haul

On a real boat the sailor pushes the tiller and the boom in the same direction,

here find out which side the boom is already on and push the tiller that way (rotate rudder opposite to direction of windvane)

1. Get Relative Wind angle and check if within +-45°

2. If so, Get sign of relative wind angle.

3.Set rudder to “sign” * 45° or so to swing stern out

Command Motors to specified positions

Go back to step 1

4. If not, switch to close haul code

Flowchart for Beat UpWind

PROGRAM Beat UpWind

TOP OF CODE

Include libraries , set up I/O

Define constants and limits

Define variables

Define flags for verbose, manual/autonomous

unsigned long duration;

SETUP ()

Set up Windsensor, servos, serial monitor, input transmitter

code to read GPS using interrupts

LOOP()

Timerloop to sail for 15 sec then tack. Tack takes as long as it needs

Read transmitter inputs

Read all sensor values (wind, compass, GPS)

Calculate Absolut Wind, Absolute and relative angles to WP

if(timeToTack){

tack();

timeToTack=false;

time = millis(); // reset timer

}

closeHaul CODE

if ((millis() - time) > 15000) timeToTack=true; //tack

FUNCTION void commandMotor(int pos, int servoname)

FUNCTION void readTransmitter() READ

FUNCTION int getRelativeWind() READ

FUNCTION void tack(int newRelWind)

FUNCTION float getAbsBoatHeading() READ

FUNCTION void getAbsBoatPosition() READ

FUNCTION float getAbsWind(float rWind, float aBoatHeading) CALCULATE

FUNCTION float getAbsAngleToWaypoint(float wpX, float wpY, float boatX, float boatY) CALCULATE

FUNCTION float getRelativeAngleToWaypoint(float absAngle, float boatHeading) CALCULATE

FUNCTION void latLonToUTM(float lat, float lon) CALCULATE

FUNCTION float normalize0To360(float angle) CALCULATE

FUNCTION float normalizeN180ToP180(float angle) CALCULATE

FUNCTION float angleBetweenTwoPoints(float p2X, float p2Y, float p1X, float p1Y) CALCULATE

Algorithms – Write, Code, Flowchart, Draw, etc. for Basic Maneuvers, then combine to do more complicated tasks in Project

**Basic maneuvers:**- Tacking - turn bow 90° through wind
- Jibing turn stern 90° through wind
- Getting out of irons
- Knowing when to tack
- Correcting course to follow a desired compass angle (heading)
- tacking > 90° (go side to side)
- Controlling speed
- Knowing if desired direction is in go/no-go ranges
- Know when you have crossed desired “line”
- Know when you have reached desired waypoint

**Project:**

Develop algorithm and code for 3 sailing challenges and demonstrate them with your boat.

Choose from these tasks:

1. Beating-upwind course –

Starting behind a “line”, sail upwind to cross another line approx. 30m upwind.

Finish position should be with +-15 meters side to side

2. Run-downwind course –

Starting behind a “line”, sail downwind to cross another line approx. 30m upwind. Include at least 1 jibe

Finish position should be with +-15 meters side to side

3. Station keeping course –

Boats will sail into a 20 m x 20 m "box" formed by four buoys with known GPS locations.

The boats should to remain in the box for a given amount of time, then exit the box.

4. Sail at compass angle

Sail at a given heading from a starting point. Given heading will not be in the no-go range. Make one course change to another given angle (no tack or jibe required)

5. Sail to WayPoint

Sail to within 3 meters of a waypoint from a given starting position that is approximately 20 meters away

6. Get out of Irons

Sail into irons, wait for 10 seconds or so, then get out of irons and sail away on a port tack

-----------------------------------------------------------------------------------------------------------------------

Starter code:

Write/describe the commands you would send to the rudder servo motor and the sail winch servo motor. (you can start with manual rudder if you like)

Sail at close-hauled or any other angle

Given: Wind angle to sail, Close Haul = 45°

1. Get Relative Wind angle and compare to desired angle

2. Compare to desired angle in a set of “if” statements for ranges of relative wind values.

3. Calculate desired rudder and sail angles for each cases

4. Command Motors to specified positions

5. Go back to step 1

6. Consider holding rudder in slightly to counter rounding up due to heel (rudderCMD) sign(RelWind)*20

Sail at compass angle

Given: Direction to sail from a compass (could be from a compass or from a waypoint calculation)

need to turn rudder and have sail adjust appropriately for wind

1. Get Compass heading and RelativeWindDirection

2. Calculate heading change needed RelAngletoWP = AbsAngletoWP - Compass

3. Compare angles in a set of “if” statements for ranges of relative wind values.

4. Calculate desired rudder for each case.

5. Sail follows wind direction

6. Command Motors to specified positions

7. Go back to step 1

8. Think about how to stay on desired angle – will drift off

Sail to WayPoint

Given: GPS location of destination, GPS of current boat position

1. Get GPS location, Compass heading and RelativeWindDirection

2. Calculate heading change needed RelAngletoWP = AbsAngletoWP - Compass

3. Compare angles in a set of “if” statements for ranges of relative wind values.

4. Calculate desired rudder for each case.

5. Sail follows wind direction

6. Command Motors to specified positions

7. Check distance from location – if too big Go back to step 1

else return and get position of next waypoint

Get out of Irons

Need to back out of irons and get in to position where you can sail off in close haul

On a real boat the sailor pushes the tiller and the boom in the same direction,

here find out which side the boom is already on and push the tiller that way (rotate rudder opposite to direction of windvane)

1. Get Relative Wind angle and check if within +-45°

2. If so, Get sign of relative wind angle.

3.Set rudder to “sign” * 45° or so to swing stern out

Command Motors to specified positions

Go back to step 1

4. If not, switch to close haul code

Flowchart for Beat UpWind

PROGRAM Beat UpWind

TOP OF CODE

Include libraries , set up I/O

Define constants and limits

Define variables

Define flags for verbose, manual/autonomous

unsigned long duration;

SETUP ()

Set up Windsensor, servos, serial monitor, input transmitter

code to read GPS using interrupts

LOOP()

Timerloop to sail for 15 sec then tack. Tack takes as long as it needs

Read transmitter inputs

Read all sensor values (wind, compass, GPS)

Calculate Absolut Wind, Absolute and relative angles to WP

if(timeToTack){

tack();

timeToTack=false;

time = millis(); // reset timer

}

closeHaul CODE

if ((millis() - time) > 15000) timeToTack=true; //tack

FUNCTION void commandMotor(int pos, int servoname)

FUNCTION void readTransmitter() READ

FUNCTION int getRelativeWind() READ

FUNCTION void tack(int newRelWind)

FUNCTION float getAbsBoatHeading() READ

FUNCTION void getAbsBoatPosition() READ

FUNCTION float getAbsWind(float rWind, float aBoatHeading) CALCULATE

FUNCTION float getAbsAngleToWaypoint(float wpX, float wpY, float boatX, float boatY) CALCULATE

FUNCTION float getRelativeAngleToWaypoint(float absAngle, float boatHeading) CALCULATE

FUNCTION void latLonToUTM(float lat, float lon) CALCULATE

FUNCTION float normalize0To360(float angle) CALCULATE

FUNCTION float normalizeN180ToP180(float angle) CALCULATE

FUNCTION float angleBetweenTwoPoints(float p2X, float p2Y, float p1X, float p1Y) CALCULATE

programming_tasks.docx | |

File Size: | 633 kb |

File Type: | docx |