Exemplo n.º 1
0
bool PlaylistDAO::appendTracksToPlaylist(const QList<int>& trackIds, const int playlistId) {
    // qDebug() << "PlaylistDAO::appendTracksToPlaylist"
    //          << QThread::currentThread() << m_database.connectionName();

    // Start the transaction
    ScopedTransaction transaction(m_database);

    int position = getMaxPosition(playlistId);

    // Append after the last song. If no songs or a failed query then 0 becomes 1.
    ++position;

    //Insert the song into the PlaylistTracks table
    QSqlQuery query(m_database);
    query.prepare("INSERT INTO PlaylistTracks (playlist_id, track_id, position, pl_datetime_added)"
                  "VALUES (:playlist_id, :track_id, :position, CURRENT_TIMESTAMP)");
    query.bindValue(":playlist_id", playlistId);


    int insertPosition = position;
    foreach (int trackId, trackIds) {
        query.bindValue(":track_id", trackId);
        query.bindValue(":position", insertPosition++);
        if (!query.exec()) {
            LOG_FAILED_QUERY(query);
            return false;
        }
    }
Exemplo n.º 2
0
  ///Initialize motor params
  foreach( Servo *s, motors )
  {
	Servo::TMotorData &data = s->data;
	RoboCompJointMotor::MotorParams &params = s->params;
	
	std::cout << "JointMotor::Dynamixel::Dynamixel - Configuration data of motor " << params.name << std::endl;
	///Set Status return level to 1. Level 0: no response ; Level 1: only for reading commands. Default ; Level 2: always
	int level = 1;
	setStatusReturnLevel(params.busId, level);
	getStatusReturnLevel(params.busId, level);
	qDebug() << "	Status return level: " << level;
	
	///Return delay time
	int rt = 50;
	if (setReturnDelayTime( params.busId, rt) == true and getReturnDelayTime( params.busId, rt) == true)
	{
	  qDebug() << "	Return delay time: " << rt;
	}
	else
	  qDebug() << "Error setting delay time";
	
	///Control params
	int m;
	if (getPunch( params.busId, m ) == true)
	{
	  qDebug() << "	Punch: " << m;
	}
	else
	  qDebug() << "Error reading Punch";
	
	if (getCCWComplianceMargin( params.busId, m ) == true)
	{
	  qDebug() << "	CCWComplianceMargin: " << m;
	}
	else
	  qDebug() << "Error reading CCWComplianceMargin";  
	
	if (getCWComplianceMargin( params.busId, m ) == true)
	{
	  qDebug() << "	CWComplianceMargin: " << m;
	}
	else
	  qDebug() << "Error reading CWComplianceMargin";  
	if (getCCWComplianceSlope( params.busId, m ) == true)
	{
	  qDebug() << "	CCWComplianceSlope: " << m;
	}
	else
	  qDebug() << "Error reading CCWComplianceSlope";  
	
	if (getCWComplianceSlope( params.busId, m ) == true)
	{
	  qDebug() << "	CWComplianceSlope: " << m;
	}
	else
	  qDebug() << "Error reading CWComplianceSlope";  
	
	
	///Read current position
	int p;
	getPosition(params.busId, p );
	data.currentPos  = p;
	data.antPos = p;
	data.currentPosRads = s->steps2Rads(p);
	qDebug() << "	Current position (steps): " << data.currentPos;
	qDebug() << "	Current position (rads): " << data.currentPosRads;
	
	///Set limits
	setMaxPosition(params.busId, MAXSTEPSPOSITION);
	setMinPosition(params.busId, MINSTEPSPOSITION);	
	
	getMaxPosition( params.busId, p);
	qDebug() << "	Max position (steps): " << params.maxPos <<  p;
	getMinPosition( params.busId, p);
	qDebug() << "	Min position (steps): " << params.minPos << p;
	
	///set servos to maximum speed
	setVelocity( params.busId, params.maxVelocity);
	
	qDebug() << "	Max velocity " << params.maxVelocity;
	
 	setBothComplianceMargins(params.busId, 2);	
 	setBothComplianceSlopes(params.busId, 120);
//         setPunch(params.busId, 50);

  }