Week 15

Using the existing servo code I changed  the program to move the control arms.

This is the rudder control program

#include <Servo.h>

Servo rudder; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
rudder.attach(6); // attaches the servo on pin 6 to the servo object
}

void loop()
{
pos = 40; // Setting the rudder to it center position
rudder.write(pos);

delay(5000);
for(pos = 40; pos >= 0; pos -= 2) //Makes the rudder move from rest to full port turn
{
rudder.write(pos);
delay(500);
}

delay(5000);

for(pos = 0; pos <= 40; pos += 2){ //Returns the rudder to center position
rudder.write(pos);
delay(500);
}

for(pos = 40; pos <= 64; pos += 2){ //Makes rudder turn to full starboard
rudder.write(pos);
delay(500);
}

delay(5000);

for(pos = 64; pos >= 40; pos -= 2){ //Makes rudder turn to full starboard
rudder.write(pos);
delay(500);
}

delay(10000);

}

A similar program is run for the dive planes but more importantly I have also writen the code for the motor control

#include <Servo.h>

Servo myservo;

void arm(){
// arm the speed controller, modify as necessary for your ESC
setSpeed(50); // this is the value for rest for the motor
delay(5000); //delay 5 second, some speed controllers may need longer
}

void setSpeed(int speed){
// speed is from 0 to 100 where 0 is off and 100 is maximum speed
//the following maps speed values of 0-100 to angles from 0-180,
// some speed controllers may need different values, see the ESC instructions
int angle = map(speed, 0, 100, 0, 180);
myservo.write(angle);
}

void setup(){
myservo.attach(9);
arm();

}
void loop(){
int speed;

speed = 68; /*sets the speed variable before running the setSpeed function.
A setting of 50 is rest for the motor and the speed control.
values above 50 move it forward and values less then 50 move it in reverse.*/
setSpeed(speed);
delay(5000);
setSpeed(0);
delay(5000); // stop the motor for 5 seconds
}

Combining these to is the next step and then we can seal the subs component box and we will be ready for the ocean…..or a bath tub.

This entry was posted in journals. Bookmark the permalink.

2 Responses to Week 15

  1. stephanie s says:

    Mike, I have to tell you – I am really proud of this code. I think we did a great job of determining our goal and achieving it. The way we broke it down into steps and tested each component ensured that when we put it all together it would work perfectly!

    The only concern I have now is about executing the program in water. IF the sub actually makes it into the pool on Tuesday and IF we are able to seal the watertight components properly who the hell knows where the it will wind up? Yes, we programed it to turn and dive but we really don’t know what that looks like in the real world…….

  2. michaelp85 says:

    hmmmm, I see why you are concerned perhaps We can play around with the timing of the turns to try to keep it near us. Also maybe We can set the motor to a lower speed setting. Either of these I think is a viable option.

Leave a Reply