Salut,
being fed up with the discussion about the slow sparki I applied an interim fix to sparki.ccp and sparki.h. Both can be found in the libraries\sparki subdirectory, either in the SprakiIDE directory tree or in the Arduino sketchbook directory tree.
I added the following variables to sparki.h (right at the start of the class definition, MOW are my initials):
[code]public:
SparkiClass();
/// MOW - additions
int M_maxSpeedLeft; // maximum motor speed for the left motor, allowing a motor specific setting if needed
int M_maxSpeedRight; // maximum motor speed for the right motor, allowing a motor specific setting if needed
int M_maxSpeedGripper; // maximum motor speed for the gripper motor
int M_turnSpeedLeft; // speed for left turn in percent of max speed
int M_turnSpeedRight; // speed for right turn in percent of max speed
int M_pctSpeedLeft; // speed of motor in percent of max speed
int M_pctSpeedRight; // speed of motor in percent of max speed
int M_pctSpeedGripper; // speed of motor in percent of max speed
/// MOW - additions END
[/code]
in sparki.cpp (staring at line 311) I changed the calls to the motorRotate to map the percent to the max values ( I commented out the original code and marked all changes with my initials):
void SparkiClass::moveRight()
{
// MOW
// motorRotate(MOTOR_LEFT, DIR_CCW, 100);
// motorRotate(MOTOR_RIGHT, DIR_CCW, 100);
motorRotate(MOTOR_LEFT, DIR_CCW, map(M_turnSpeedLeft,0,100,0,M_maxSpeedLeft));
motorRotate(MOTOR_RIGHT, DIR_CCW, map(M_turnSpeedRight,0,100,0,M_maxSpeedRight));
// MOW END
}
void SparkiClass::moveLeft(float deg)
{
float turn = 21.388888*deg;
moveLeft();
delay(long(turn));
moveStop();
}
void SparkiClass::moveLeft()
{
// MOW
// motorRotate(MOTOR_LEFT, DIR_CW, 100);
// motorRotate(MOTOR_RIGHT, DIR_CW, 100);
motorRotate(MOTOR_LEFT, DIR_CW, map(M_turnSpeedLeft,0,100,0,M_maxSpeedLeft));
motorRotate(MOTOR_RIGHT, DIR_CW, map(M_turnSpeedRight,0,100,0,M_maxSpeedRight));
// MOW END
}
void SparkiClass::moveForward(float cm)
{
float run = 222.222222*cm;
moveForward();
delay(run);
moveStop();
}
void SparkiClass::moveForward()
{
// MOW
// motorRotate(MOTOR_LEFT, DIR_CCW, 100);
// motorRotate(MOTOR_RIGHT, DIR_CW, 100);
motorRotate(MOTOR_LEFT, DIR_CCW, map(M_pctSpeedLeft,0,100,0,M_maxSpeedLeft));
motorRotate(MOTOR_RIGHT, DIR_CW, map(M_pctSpeedRight,0,100,0,M_maxSpeedRight));
// MOW END
}
void SparkiClass::moveBackward(float cm)
{
float run = 222.222222*cm;
moveBackward();
delay(run);
moveStop();
}
void SparkiClass::moveBackward()
{
// MOW
// motorRotate(MOTOR_LEFT, DIR_CW, 100);
// motorRotate(MOTOR_RIGHT, DIR_CCW, 100);
motorRotate(MOTOR_LEFT, DIR_CW, map(M_pctSpeedLeft,0,100,0,M_maxSpeedLeft));
motorRotate(MOTOR_RIGHT, DIR_CCW, map(M_pctSpeedRight,0,100,0,M_maxSpeedRight));
// MOW END
}
void SparkiClass::moveStop()
{
motorStop(MOTOR_LEFT);
motorStop(MOTOR_RIGHT);
}
void SparkiClass::gripperOpen()
{
// MOW
// motorRotate(MOTOR_GRIPPER, DIR_CCW, 100);
motorRotate(MOTOR_GRIPPER, DIR_CCW, map(M_pctSpeedGripper,0,100,0,M_maxSpeedGripper));
// MOW END
}
void SparkiClass::gripperClose()
{
// MOW
// motorRotate(MOTOR_GRIPPER, DIR_CW, 100);
motorRotate(MOTOR_GRIPPER, DIR_CW, map(M_pctSpeedGripper,0,100,0,M_maxSpeedGripper));
// MOW END
}
With this, I just have to declare my preferred speed values in the setup() routine of the sketch, here using the wall_avoidance code:
[code]#include <Sparki.h> // include the sparki library
void setup()
{
sparki.M_maxSpeedLeft = 250;
sparki.M_maxSpeedRight = 250;
sparki.M_maxSpeedGripper = 250;
sparki.M_turnSpeedLeft = 100;
sparki.M_turnSpeedRight = 100;
sparki.M_pctSpeedLeft = 100;
sparki.M_pctSpeedRight = 100;
sparki.M_pctSpeedGripper = 100;
// position the Ultrasonic sensor
sparki.servo(SERVO_CENTER);
}
void loop()
{
sparki.RGB(RGB_GREEN); // turn the light green
int cm = sparki.ping(); // measures the distance with Sparki’s eyes
sparki.moveForward();
if(cm != -1) // make sure its not too close or too far
{
if(cm < 20) // if the distance measured is less than 10 centimeters
{
sparki.RGB(RGB_RED); // turn the light red
sparki.beep(); // beep!
sparki.moveBackward(10); // back up 10 centimeters
sparki.moveRight(30); // rotate right 30 degrees
delay(1000);
}
}
delay(100); // wait 0.1 seconds (100 milliseconds)
}[/code]
With this, my sparki starts to move nicely, using 6 AA batteries.
I will check the entire lib and once finished, I will post the complete lib with all my changes flagged with my initials on this topic here.
Ciao, Mathias