Rather than have us search and guess whether we have the same information that you have, you need to give us the links.
Link to the robot.
Get the source you refer to and post it here.
Use the code tags </>
//--------------------------------------------------------------
//-- Oscillator.pde
//-- Generate sinusoidal oscillations in the servos
//--------------------------------------------------------------
//-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011
//-- GPL license
//--------------------------------------------------------------
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#include <pins_arduino.h>
#endif
#include "Oscillator.h"
#include <Servo.h>
//-- This function returns true if another sample
//-- should be taken (i.e. the TS time has passed since
//-- the last sample was taken
bool Oscillator::next_sample()
{
//-- Read current time
_currentMillis = millis();
//-- Check if the timeout has passed
if(_currentMillis - _previousMillis > _TS) {
_previousMillis = _currentMillis;
return true;
}
return false;
}
//-- Attach an oscillator to a servo
//-- Input: pin is the arduino pin were the servo
//-- is connected
void Oscillator::attach(int pin, bool rev)
{
//-- If the oscillator is detached, attach it.
if(!_servo.attached()){
//-- Attach the servo and move it to the home position
_servo.attach(pin);
_servo.write(90);
//-- Initialization of oscilaltor parameters
_TS=30;
_T=2000;
_N = _T/_TS;
_inc = 2*M_PI/_N;
_previousMillis=0;
//-- Default parameters
_A=45;
_phase=0;
_phase0=0;
_O=0;
_stop=false;
//-- Reverse mode
_rev = rev;
}
}
//-- Detach an oscillator from his servo
void Oscillator::detach()
{
//-- If the oscillator is attached, detach it.
if(_servo.attached())
_servo.detach();
}
/*************************************/
/* Set the oscillator period, in ms */
/*************************************/
void Oscillator::SetT(unsigned int T)
{
//-- Assign the new period
_T=T;
//-- Recalculate the parameters
_N = _T/_TS;
_inc = 2*M_PI/_N;
};
/*******************************/
/* Manual set of the position */
/******************************/
void Oscillator::SetPosition(int position)
{
_servo.write(position+_trim);
};
/*******************************************************************/
/* This function should be periodically called */
/* in order to maintain the oscillations. It calculates */
/* if another sample should be taken and position the servo if so */
/*******************************************************************/
void Oscillator::refresh()
{
//-- Only When TS milliseconds have passed, the new sample is obtained
if (next_sample()) {
//-- If the oscillator is not stopped, calculate the servo position
if (!_stop) {
//-- Sample the sine function and set the servo pos
_pos = round(_A * sin(_phase + _phase0) + _O);
if (_rev) _pos=-_pos;
_servo.write(_pos+90+_trim);
}
//-- Increment the phase
//-- It is always increased, even when the oscillator is stop
//-- so that the coordination is always kept
_phase = _phase + _inc;
}
}
Not sure...... but usually, a position controlling servo is generally used to just make a robot arm or part pivot to some angular position (relative to some reference).
Maybe this oscillation thing is a code that does the same thing, except it makes the part do some kind of choreographed routine ..... like pivot back and forth in some kind of oscillatory (repeated) fashion, rather than just remaining still.
It's possible that this code basically makes the arduino do a measurement on a sinusoidal signal (from a sinusoidal source), and then it converts the measured (sampled) level to a value that the computer can work with. And then it might make the servo (angle) position mimic that value. Then the arduino takes another sample of the sinusoid signal (connected to one of the arduino's analog inputs), and the process keeps repeating. The servo's angular position is probably meant to follow the sinusoidal pattern.
Now.....because "sampling of signals" is involved, some considerations will need to be made about the sampling speed, and also how fast the servo can respond. This means.....if the sinusoidal signal's frequency is too high.....then the servo will not be able to move fast enough to replicate the signal's behaviour.
That is reasonable explanation of the phrase "software DDS", basically a time varying signal is directly
synthesized using a phase variable that is regularly incremented - the phase is looked up in a sine table
to give the sampled waveform.
There is another way to implement this that doesn't need a library:
But its got issues (millis wraps round, sin function doesn't necessarily work well with large argument
values, floating point is slow on an 8-bit microcontroller)