/*
 *  ax12syncpositionspeed.h
 *
 * $Id: ax12syncpositionspeed.h 1 2008-07-30 09:24:06Z mschneider $
 * $URL: svn://localhost/Bioloid/trunk/ax12syncpositionspeed.h $
 
 * \version   $Rev: 1 $
 * \author    Markus Schneider
 * \date      17.07.08
 *
 */

#ifndef AX12SYNCPOSITIONSPEED_H
#define AX12SYNCPOSITIONSPEED_H

#include "ax12.h"
#include "syncwritepacket.h"
#include "connection.h"

/**
 * Set a position and speed for multible AX12 syncron.
 *
 * Usage:
 *  init connection...
 *  AX12SyncPositionSpeed swp(&conn);
 *  swp.add(9, 300, 0x100);
 *  swp.add(2, 10, 0x10);
 *  swp.execute();
 *  swp.add(9, 100, 0x100);
 *  swp.add(2, 180, 0x30);
 *  swp.execute();
 *  ...
 */
class AX12SyncPositionSpeed
{
public:
  AX12SyncPositionSpeed(Connection *conn);
  
 /**
  * Add a new AX12 with position and speed to the list 
  * @param m The AX12 to add
  * @param position The goal position
  * @param speed the moving speed
  * @return Not 0 on error
  */
  virtual int add(AX12 *m, word position, word speed);
  
  /**
   * Add a new AX12 with position and speed to the list 
   * @param id The AX12-ID to add
   * @param position The goal position
   * @param speed the moving speed
   * @return Not 0 on error
   */  
  virtual int add(byte id, word position, word speed);
  
  /**
   * Resets the list - Will be also called automatically 
   * after execute()
   * @param m The AX12 to add
   * @param position The goal position
   * @param speed the moving speed
   * @return Not 0 on error
   */  
  virtual int clear();
  
  /**
   * Transmits the packet over the connection
   */
  virtual int execute();
  
protected:
  Connection *conn;
  SyncWritePacket *swp;
};

#endif
