void ItemEditorWidget::search(const QRegExp &re, bool backwards) { if ( !re.isValid() ) return; auto tc = textCursor(); if ( tc.isNull() ) return; QTextDocument::FindFlags flags; if (backwards) flags = QTextDocument::FindBackward; auto tc2 = tc.document()->find(re, tc, flags); if (tc2.isNull()) { tc2 = tc; if (backwards) tc2.movePosition(QTextCursor::End); else tc2.movePosition(QTextCursor::Start); tc2 = tc.document()->find(re, tc2, flags); } if (!tc2.isNull()) setTextCursor(tc2); }
void KTextCursor::insertHtml( const QString &text, const QMap<QString, QString>& imgs ) { if(!imgs.isEmpty()) { for(QMap<QString,QString>::const_iterator iter = imgs.begin(); iter != imgs.end(); iter++) { QString key = iter.key(); QString file = iter.value(); if(moviePool()->insertMovie(file, file)) { //修改属性为动画。 document()->addResource(QTextDocument::ImageResource, QUrl(file), moviePool()->currentImage(file)); } else { QImage image(file); if(!image.isNull()) { document()->addResource(QTextDocument::ImageResource, QUrl(file), image); } } } } int istart = position(); insertHtml(text); int inow = position(); if(!imgs.isEmpty() && inow > istart) { setPosition(istart); movePosition(NextCharacter, KeepAnchor, inow-istart); QString txt = selectedText(); int index = txt.indexOf(QChar::ObjectReplacementCharacter, 0); while(index >= 0) { /*修改字体类型。*/ setPosition(istart+index); movePosition(NextCharacter, KeepAnchor, 1); QTextCharFormat fmt = charFormat(); QTextImageFormat imgFmt = fmt.toImageFormat(); QString key = imgFmt.name(); if(imgs.contains(key)) { imgFmt.setProperty(KImageKey, key); imgFmt.setName(imgs.value(key)); imgFmt.setProperty(KAnimationImage, true); setCharFormat(imgFmt); } int idx = index+1; index = txt.indexOf(QChar::ObjectReplacementCharacter, idx); } } setPosition(inow); }
void Observation::centerPrey(const Point2D &dims) { if (positions[preyInd] == 0.5f * dims) return; Point2D offset = 0.5f * dims - absPrey; for (unsigned int i = 0; i < positions.size(); i++) positions[i] = movePosition(dims,positions[i],offset); }
void getPositionsFromState(State_t state, const Point2D &dims, std::vector<Point2D> &positions, const Point2D &preyPos, bool usePreySymmetry) { State_t origState(state); Point2D offset(0,0); int startInd = 0; if (usePreySymmetry) { startInd = 1; positions[0] = preyPos; offset = preyPos - 0.5f * dims; } for (unsigned int i = startInd; i < positions.size(); i++) { positions[i].x = state % dims.x; state /= dims.x; positions[i].y = state % dims.y; state /= dims.y; positions[i] = movePosition(dims,positions[i],offset); } if (state != 0) { std::cerr << "NOT ZERO: " << state << std::endl; std::cerr << "original state: " << origState << std::endl; std::cerr << "What we got: "; for (unsigned int i = 0; i < positions.size(); i++) std::cerr << positions[i] << " "; std::cerr << std::endl; } assert(state == 0); }
//-------------------------------------------------------------------------------------- // Initiates the manoeuvre. This mostly consists of sending initial orders to all // participating entities and everything that is involved in that process, such as // determining targets etc. // Returns a behaviour status code representing the current state of the initiation of the manoeuvre. //-------------------------------------------------------------------------------------- BehaviourStatus ActiveBaseDefence::Initiate(void) { for(std::vector<Entity*>::iterator it = m_participants.begin(); it != m_participants.end(); ++it) { // Randomly pick a grid field near the base and patrol to it. XMFLOAT2 movePosition(0.0f, 0.0f); if(!m_pTeamAI->GetTestEnvironment()->GetRandomUnblockedTargetInArea(GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition, m_patrolRadius, movePosition)) { return StatusFailure; } Order* pNewOrder = new MoveOrder((*it)->GetId(), MoveToPositionOrder, MediumPriority, movePosition); if(!pNewOrder) { return StatusFailure; } FollowOrderMessageData data(pNewOrder); SendMessage(*it, FollowOrderMessageType, &data); m_activeOrders.insert(std::pair<unsigned long, Order*>((*it)->GetId(), pNewOrder)); } return StatusSuccess; }
void Observation::uncenterPrey(const Point2D &dims) { if (absPrey == preyPos()) return; Point2D offset = absPrey - preyPos(); for (unsigned int i = 0; i < positions.size(); i++) positions[i] = movePosition(dims,positions[i],offset); }
void Camera::move(glm::vec3 const & clampMin, glm::vec3 const & clampMax) { movePosition(); Utils::clamp(position_, clampMin, clampMax); moveOrientation(); updateEyeTarget(); }
//-------------------------------------------------------------------------------------- // Processes an inbox message that the manoeuvre received. // Param1: A pointer to the message to process. //-------------------------------------------------------------------------------------- void ActiveBaseDefence::ProcessMessage(Message* pMessage) { switch(pMessage->GetType()) { case FlagPickedUpMessageType: { FlagPickedUpMessage* pMsg = reinterpret_cast<FlagPickedUpMessage*>(pMessage); if(pMsg->GetData().m_flagOwner == GetTeamAI()->GetTeam()) { // The team's flag was picked up, the manoeuvre failed SetFailed(true); } break; } case EntityKilledMessageType: { EntityKilledMessage* pMsg = reinterpret_cast<EntityKilledMessage*>(pMessage); if(IsParticipant(pMsg->GetData().m_id) && pMsg->GetData().m_team == GetTeamAI()->GetTeam()) { XMFLOAT2 deathPosition = GetParticipant(pMsg->GetData().m_id)->GetPosition(); // Participants that get killed, drop out of the manoeuvre m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_id); // Send other participants to investigate the position, where the entity died InvestigatePosition(deathPosition); } break; } case UpdateOrderStateMessageType: { // Cancel old order, Send Follow-Up Orders, finish manoeuvre etc UpdateOrderStateMessage* pMsg = reinterpret_cast<UpdateOrderStateMessage*>(pMessage); if(IsParticipant(pMsg->GetData().m_entityId)) { if(pMsg->GetData().m_orderState == SucceededOrderState) { XMFLOAT2 movePosition(0.0f, 0.0f); if(!m_pTeamAI->GetTestEnvironment()->GetRandomUnblockedTargetInArea(GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition, m_patrolRadius, movePosition)) { m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_entityId); }else { // Set the next patrol target reinterpret_cast<MoveOrder*>(m_activeOrders[pMsg->GetData().m_entityId])->SetTargetPosition(movePosition); } }else if(pMsg->GetData().m_orderState == FailedOrderState) { m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_entityId); } } break; } default: TeamManoeuvre::ProcessMessage(pMessage); } }
void SampleTCO::loadSettings( const QDomElement & _this ) { if( _this.attribute( "pos" ).toInt() >= 0 ) { movePosition( _this.attribute( "pos" ).toInt() ); } setSampleFile( _this.attribute( "src" ) ); if( sampleFile().isEmpty() && _this.hasAttribute( "data" ) ) { m_sampleBuffer->loadFromBase64( _this.attribute( "data" ) ); } changeLength( _this.attribute( "len" ).toInt() ); setMuted( _this.attribute( "muted" ).toInt() ); }
void pattern::loadSettings( const QDomElement & _this ) { unfreeze(); m_patternType = static_cast<PatternTypes>( _this.attribute( "type" ).toInt() ); setName( _this.attribute( "name" ) ); if( _this.attribute( "pos" ).toInt() >= 0 ) { movePosition( _this.attribute( "pos" ).toInt() ); } changeLength( MidiTime( _this.attribute( "len" ).toInt() ) ); if( _this.attribute( "muted" ).toInt() != isMuted() ) { toggleMute(); } clearNotes(); QDomNode node = _this.firstChild(); while( !node.isNull() ) { if( node.isElement() && !node.toElement().attribute( "metadata" ).toInt() ) { note * n = new note; n->restoreState( node.toElement() ); m_notes.push_back( n ); } node = node.nextSibling(); } m_steps = _this.attribute( "steps" ).toInt(); if( m_steps == 0 ) { m_steps = MidiTime::stepsPerTact(); } ensureBeatNotes(); checkType(); /* if( _this.attribute( "frozen" ).toInt() ) { freeze(); }*/ emit dataChanged(); updateBBTrack(); }
void bbTCO::loadSettings( const QDomElement & _this ) { setName( _this.attribute( "name" ) ); if( _this.attribute( "pos" ).toInt() >= 0 ) { movePosition( _this.attribute( "pos" ).toInt() ); } changeLength( _this.attribute( "len" ).toInt() ); if( _this.attribute( "muted" ).toInt() != isMuted() ) { toggleMute(); } if( _this.attribute( "color" ).toUInt() != 0 ) { m_color = _this.attribute( "color" ).toUInt(); } }
void PredatorSurroundWithPenalties::setPenaltyMode(const Observation &obs) { int stepViolations = 0; if (!captureMode && usePrevObs) { for (int i = 0; i < NUM_PREDATORS; i++) { //if (i+1 == (int)obs.myInd) // +1 because prey is 0 //continue; if (expectedMoves[i] == Action::NUM_ACTIONS) continue; // wasn't sure what that guy was going to do Point2D move = getDifferenceToPoint(dims,prevObs.positions[i+1],obs.positions[i+1]); Point2D desiredPosition = movePosition(dims,prevObs.positions[i+1],expectedMoves[i]); bool desiredPositionOccupied = false; for (unsigned int j = 0; j < obs.positions.size(); j++) { if ((desiredPosition == obs.positions[j]) || (desiredPosition == prevObs.positions[j])){ desiredPositionOccupied = true; break; } } if (desiredPositionOccupied) continue; if (move != Action::MOVES[expectedMoves[i]]) { stepViolations++; //std::cout << prevObs.positions[i+1] << " " << obs.positions[i+1] << " " << i+1 << " " << desiredPosition << std::endl; //std::cout << prevObs << " " << obs << " " << i << " " << desiredPosition << std::endl; break; } } } // add the violation count to the history while (violationHistory.size() >= violationHistorySize) violationHistory.pop_front(); violationHistory.push_back(stepViolations); // check the number of violations in history int numViolations = 0; for (unsigned int i = 0; i < violationHistory.size(); i++) numViolations += violationHistory[i]; //std::cout << "NUM VIOLATIONS: " << numViolations << std::endl; if (numViolations >= numViolationsToPenalize) penaltyOn = true; else penaltyOn = false; }
void AutomationPattern::loadSettings( const QDomElement & _this ) { clear(); movePosition( _this.attribute( "pos" ).toInt() ); setName( _this.attribute( "name" ) ); setProgressionType( static_cast<ProgressionTypes>( _this.attribute( "prog" ).toInt() ) ); setTension( _this.attribute( "tens" ) ); setMuted(_this.attribute( "mute", QString::number( false ) ).toInt() ); for( QDomNode node = _this.firstChild(); !node.isNull(); node = node.nextSibling() ) { QDomElement element = node.toElement(); if( element.isNull() ) { continue; } if( element.tagName() == "time" ) { m_timeMap[element.attribute( "pos" ).toInt()] = element.attribute( "value" ).toFloat(); } else if( element.tagName() == "object" ) { m_idsToResolve << element.attribute( "id" ).toInt(); } } int len = _this.attribute( "len" ).toInt(); if( len <= 0 ) { // TODO: Handle with an upgrade method updateLength(); } else { changeLength( len ); } generateTangents(); }
void BBTCO::loadSettings( const QDomElement & element ) { setName( element.attribute( "name" ) ); if( element.attribute( "pos" ).toInt() >= 0 ) { movePosition( element.attribute( "pos" ).toInt() ); } changeLength( element.attribute( "len" ).toInt() ); if( element.attribute( "muted" ).toInt() != isMuted() ) { toggleMute(); } if( element.hasAttribute( "color" ) ) { setColor( QColor( element.attribute( "color" ).toUInt() ) ); } if( element.hasAttribute( "usestyle" ) ) { if( element.attribute( "usestyle" ).toUInt() == 1 ) { m_useStyleColor = true; } else { m_useStyleColor = false; } } else { if( m_color.rgb() == qRgb( 128, 182, 175 ) || m_color.rgb() == qRgb( 64, 128, 255 ) ) // old or older default color { m_useStyleColor = true; } else { m_useStyleColor = false; } } }
State_t getStateFromObs(const Point2D &dims, const Observation &obs, bool usePreySymmetry) { State_t state = 0; Point2D pos; Point2D offset(0,0); int endInd = 0; if (usePreySymmetry) { // move the first agent to the center offset = (0.5f * dims) - obs.positions[0]; endInd = 1; } for (int i = ((int)obs.positions.size())-1; i >= endInd; i--) { pos = obs.positions[i]; pos = movePosition(dims,pos,offset); state *= dims.y; state += pos.y; state *= dims.x; state += pos.x; } return state; }
/*! \reimp */ void HbScrollBar::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) { Q_D(HbScrollBar); QGraphicsWidget::mouseMoveEvent(event); if ( !d->mInteractive ) { return; } if (d->mThumbPressed) { qreal newPosition(0); QPointF movePosition(0, 0); switch (orientation()) { case Qt::Horizontal: newPosition = (event->pos().x() - d->mPressPosition.x()) / (boundingRect().width() - d->handleItem->boundingRect().width()); movePosition.setX(event->pos().x()); break; case Qt::Vertical: newPosition = (event->pos().y() - d->mPressPosition.y()) / (boundingRect().height() - d->handleItem->boundingRect().height()); movePosition.setY(event->pos().y()); break; } HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousDragged); qreal newValue = qBound(qreal(0.0), newPosition, qreal(1.0)); if (!d->emittedPos || (qAbs(d->lastEmittedPos.x() - movePosition.x()) >= qreal(THRESHOLD_VALUE)) || (qAbs(d->lastEmittedPos.y() - movePosition.y()) >= qreal(THRESHOLD_VALUE))) { setValue(newValue); d->lastEmittedPos = movePosition; d->emittedPos = true; emit valueChanged(newValue, orientation()); } } }
Point2D movePosition(const Point2D &dims, Point2D pos, Action::Type action) { return movePosition(dims,pos,Action::MOVES[action]); }
template<> void QConsoleWidget::_pf<void, SetToCommand>( QConsoleWidget * thisp,QList<QConsoleWidgetCommand> command ) { //TODO: ... auto tc = thisp->textCursor(); tc.setPosition( thisp->promptEndPos_); tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor,0); thisp->setTextCursor( tc ); if ( command.empty() ) { tc.removeSelectedText(); thisp->setTextCursor(tc); return ; } auto tryAddReturn = [](const QString & str)->QString { if (str.isEmpty()) { return str; } if (str.endsWith("\n")) { return str; } return (str + "\n"); }; if (command.size()==1 ) { thisp->insertPlainText( command.begin()->command ); } else if (command.size() == 2) { auto b0 = command.begin(); auto b1 = b0 + 1; if (b1->command.isEmpty()) { thisp->insertPlainText(b0->command); } else { thisp->insertPlainText(tryAddReturn(b0->command)); thisp->insertPlainText(b1->command); } } else { auto b = command.begin(); auto e = command.end() - 2; for (;b!=e;++b ) { const QString & temp = tryAddReturn( b->command ); if (temp.isEmpty() == false) { thisp->insertPlainText(temp); } } b = e; e = e + 1; if (e->command.isEmpty()) { thisp->insertPlainText(b->command); } else { thisp->insertPlainText(tryAddReturn(b->command)); thisp->insertPlainText(e->command); } } }
void AStar::plan(const Point2D &start, const Point2D &goal, const std::vector<Point2D> &obstacles) { // set the goal, and clear the previous plan this->goal = goal; clear(); goalNode.reset(); assert(start != goal); boost::shared_ptr<Node> newNode; Point2D pos; //std::set<boost::shared_ptr<Node> >::iterator it; boost::unordered_set<boost::shared_ptr<Node> >::iterator it; // start the open nodes boost::shared_ptr<Node> node(new Node(0,0,start,boost::shared_ptr<Node>())); setHeuristic(node); openHeap.push_back(node); openNodes.insert(node); // set obstacles as closed nodes for (unsigned int i = 0; i < obstacles.size(); i++) { if (obstacles[i] != goal) // ignore any obstacles at the goal closedNodes.insert(boost::shared_ptr<Node>(new Node(0,0,obstacles[i],boost::shared_ptr<Node>()))); } // while there are open nodes while (openNodes.size() > 0) { node = openHeap.front(); // get the lowest cost node if (node->pos == goal) { // we're done goalNode = node; break; } // move the node from open to closed std::pop_heap(openHeap.begin(),openHeap.end(),cmp); // resort the heap openHeap.pop_back(); // remove the node from the heap openNodes.erase(node); // remove the node from the open set closedNodes.insert(node); // add the node to the closed set // search its neighbors for (unsigned int i = 0; i < Action::NUM_NEIGHBORS; i++) { pos = movePosition(dims,node->pos,(Action::Type)i); newNode = boost::shared_ptr<Node>(new Node(node->gcost + 1,0,pos,node)); if (closedNodes.count(newNode) > 0) { continue; } it = openNodes.find(newNode); if (it != openNodes.end()) { // already open if ((*it)->gcost > newNode->gcost) { (*it)->gcost = newNode->gcost; (*it)->parent = node; // have to resort because this item might be out of place now std::make_heap(openHeap.begin(),openHeap.end(),cmp); } } else { // new open node setHeuristic(newNode); openNodes.insert(newNode); openHeap.push_back(newNode); std::push_heap(openHeap.begin(),openHeap.end(),cmp); } } } }
InstancePtr FeatureExtractor::extract(const Observation &obs, FeatureExtractorHistory &history) { TIC(total); assert(obs.preyInd == 0); InstancePtr instance(new Instance); TIC(pos); setFeature(instance,FeatureType::PredInd,obs.myInd - 1); // positions of agents for (unsigned int i = 0; i < obs.positions.size(); i++) { Point2D diff = getDifferenceToPoint(dims,obs.myPos(),obs.positions[i]); unsigned int key = FeatureType::Prey_dx + 2 * i; setFeature(instance,key,diff.x); setFeature(instance,key+1,diff.y); } TOC(pos); // derived features TIC(derived); bool next2prey = false; for (unsigned int a = 0; a < Action::NUM_NEIGHBORS; a++) { Point2D pos = movePosition(dims,obs.myPos(),(Action::Type)a); bool occupied = false; for (unsigned int i = 0; i < obs.positions.size(); i++) { if (i == obs.myInd) continue; if (obs.positions[i] == pos) { occupied = true; if (i == 0) next2prey = true; break; } } setFeature(instance,FeatureType::Occupied_0 + a, occupied); } setFeature(instance,FeatureType::NextToPrey,next2prey); TOC(derived); // actions predicted by models TIC(actions); // not currently supported //ActionProbs actionProbs; for (std::vector<FeatureAgent>::iterator it = featureAgents.begin(); it != featureAgents.end(); it++) { std::cerr << "FeatureExtractor can't handle featureAgents" << std::endl; exit(58); //actionProbs = it->agent->step(obs); //ADD_KEY(it->name + ".des"); //setFeature(instance,actionProbs.maxAction()); } TOC(actions); // update the history TIC(history); updateHistory(obs,history); // add the history features TIC(historyupdate); Action::Type action; for (unsigned int j = 0; j < HISTORY_SIZE; j++) { if (j < history.actionHistory[obs.myInd].size()) action = history.actionHistory[obs.myInd][j]; else action = Action::NUM_ACTIONS; setFeature(instance,FeatureType::MyHistoricalAction_0 + j,action); } TOC(historyupdate); /* for (unsigned int agentInd = 0; agentInd < obs.positions.size(); agentInd++) { for (unsigned int j = 0; j < HISTORY_SIZE; j++) { if (j < history.actionHistory[agentInd].size()) action = history.actionHistory[agentInd][j]; else action = Action::NUM_ACTIONS; if (USE_ALL_AGENTS_HISTORY) { std::cerr << "FeatureExtractor can't handle all agents history" << std::endl; exit(58); //ADD_KEY("HistoricalAction" + boost::lexical_cast<std::string>(agentInd) + "." + boost::lexical_cast<std::string>(j)); //setFeature(instance,action); } if (agentInd == obs.myInd) { setFeature(instance,FeatureType::MyHistoricalAction_0 + j,action); } } } */ TOC(history); instance->weight = 1.0; TOC(total); //std::cout << "instance: " << *instance << std::endl; return instance; }
static void motorHandleOneArg(const char *myarg_1) { const char *myarg = myarg_1; int iValue = 0; double fValue = 0; int motor_axis_no = 0; int nvals = 0; /* ADSPORT= */ if (!strncmp(myarg_1, ADSPORT_equals_str, strlen(ADSPORT_equals_str))) { int err_code; myarg_1 += strlen(ADSPORT_equals_str); err_code = motorHandleADS_ADR(myarg_1); if (err_code == -1) return; if (err_code == 0) { cmd_buf_printf("OK"); return; } RETURN_OR_DIE("%s/%s:%d myarg_1=%s err_code=%d", __FILE__, __FUNCTION__, __LINE__, myarg_1, err_code); } /* Main.*/ if (!strncmp(myarg_1, Main_dot_str, strlen(Main_dot_str))) { myarg_1 += strlen(Main_dot_str); } /* From here on, only M1. commands */ /* e.g. M1.nCommand=3 */ nvals = sscanf(myarg_1, "M%d.", &motor_axis_no); if (nvals != 1) { RETURN_OR_DIE("%s/%s:%d line=%s nvals=%d", __FILE__, __FUNCTION__, __LINE__, myarg, nvals); } AXIS_CHECK_RETURN(motor_axis_no); myarg_1 = strchr(myarg_1, '.'); if (!myarg_1) { RETURN_OR_DIE("%s/%s:%d line=%s missing '.'", __FILE__, __FUNCTION__, __LINE__, myarg); } myarg_1++; /* Jump over '.' */ if (0 == strcmp(myarg_1, "bBusy?")) { cmd_buf_printf("%d", isMotorMoving(motor_axis_no)); return; } /* bError? */ if (!strcmp(myarg_1, "bError?")) { cmd_buf_printf("%d", get_bError(motor_axis_no)); return; } /* bEnable? bEnabled? Both are the same in the simulator */ if (!strcmp(myarg_1, "bEnable?") || !strcmp(myarg_1, "bEnabled?")) { cmd_buf_printf("%d",getAmplifierOn(motor_axis_no)); return; } /* bExecute? */ if (!strcmp(myarg_1, "bExecute?")) { cmd_buf_printf("%d", cmd_Motor_cmd[motor_axis_no].bExecute); return; } /* bHomeSensor? */ if (0 == strcmp(myarg_1, "bHomeSensor?")) { cmd_buf_printf("%d", getAxisHome(motor_axis_no)); return; } /* bLimitBwd? */ if (0 == strcmp(myarg_1, "bLimitBwd?")) { cmd_buf_printf("%d", getNegLimitSwitch(motor_axis_no) ? 0 : 1); return; } /* bLimitFwd? */ if (0 == strcmp(myarg_1, "bLimitFwd?")) { cmd_buf_printf("%d", getPosLimitSwitch(motor_axis_no) ? 0 : 1); return; } /* bHomed? */ if (0 == strcmp(myarg_1, "bHomed?")) { cmd_buf_printf("%d", getAxisHomed(motor_axis_no) ? 1 : 0); return; } /* bReset? */ if (!strcmp(myarg_1, "bReset?")) { cmd_buf_printf("%d",cmd_Motor_cmd[motor_axis_no].bReset); return; } /* fAcceleration? */ if (0 == strcmp(myarg_1, "fAcceleration?")) { cmd_buf_printf("%g", cmd_Motor_cmd[motor_axis_no].acceleration); return; } /* fActPosition? */ if (0 == strcmp(myarg_1, "fActPosition?")) { cmd_buf_printf("%g", getMotorPos(motor_axis_no)); return; } /* fActVelocity? */ if (0 == strcmp(myarg_1, "fActVelocity?")) { cmd_buf_printf("%g", getMotorVelocity(motor_axis_no)); return; } /* fPosition? */ if (0 == strcmp(myarg_1, "fPosition?")) { /* The "set" value */ cmd_buf_printf("%g", cmd_Motor_cmd[motor_axis_no].position); return; } /* nCommand? */ if (0 == strcmp(myarg_1, "nCommand?")) { cmd_buf_printf("%d", cmd_Motor_cmd[motor_axis_no].command_no); return; } /* nMotionAxisID? */ if (0 == strcmp(myarg_1, "nMotionAxisID?")) { /* The NC axis id is the same as motion axis id */ printf("%s/%s:%d %s(%d)\n", __FILE__, __FUNCTION__, __LINE__, myarg_1, motor_axis_no); cmd_buf_printf("%d", motor_axis_no); return; } /* stAxisStatus? */ if (0 == strcmp(myarg_1, "stAxisStatus?")) { /* getMotorPos must be first, it calls simulateMotion() */ double fActPostion = getMotorPos(motor_axis_no); int bEnable = getAmplifierOn(motor_axis_no); int bReset = 0; int bExecute = cmd_Motor_cmd[motor_axis_no].bExecute; unsigned nCommand = 0; unsigned nCmdData = cmd_Motor_cmd[motor_axis_no].nCmdData; double fVelocity = 0; double fPosition = 0; double fAcceleration = 0; double fDecceleration = 0; int bJogFwd = 0; int bJogBwd = 0; int bLimitFwd = getPosLimitSwitch(motor_axis_no) ? 0 : 1; int bLimitBwd = getNegLimitSwitch(motor_axis_no) ? 0 : 1; double fOverride = 0; int bHomeSensor = getAxisHome(motor_axis_no); int bEnabled = bEnable; int bError = get_bError(motor_axis_no); int nErrorId = get_nErrorId(motor_axis_no); double fActVelocity = getMotorVelocity(motor_axis_no); double fActDiff = 0; int bHomed = getAxisHomed(motor_axis_no); int bBusy = isMotorMoving(motor_axis_no); cmd_buf_printf("Main.M%d.stAxisStatus=" "%d,%d,%d,%u,%u,%g,%g,%g,%g,%d," "%d,%d,%d,%g,%d,%d,%d,%u,%g,%g,%g,%d,%d", motor_axis_no, bEnable, /* 1 */ bReset, /* 2 */ bExecute, /* 3 */ nCommand, /* 4 */ nCmdData, /* 5 */ fVelocity, /* 6 */ fPosition, /* 7 */ fAcceleration, /* 8 */ fDecceleration, /* 9 */ bJogFwd, /* 10 */ bJogBwd, /* 11 */ bLimitFwd, /* 12 */ bLimitBwd, /* 13 */ fOverride, /* 14 */ bHomeSensor, /* 15 */ bEnabled, /* 16 */ bError, /* 17 */ nErrorId, /* 18 */ fActVelocity, /* 19 */ fActPostion, /* 20 */ fActDiff, /* 21 */ bHomed, /* 22 */ bBusy /* 23 */ ); return; } /* sErrorMessage? */ if (!strcmp(myarg_1, "sErrorMessage?")) { char buf[32]; /* 9 should be OK */ int nErrorId = get_nErrorId(motor_axis_no); snprintf(buf, sizeof(buf), "%x", nErrorId); cmd_buf_printf("%s", buf); return; } /* End of "get" commands, from here, set commands */ /* nCommand=3 */ nvals = sscanf(myarg_1, "nCommand=%d", &iValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].command_no = iValue; cmd_buf_printf("OK"); return; } /* nCmdData=1 */ nvals = sscanf(myarg_1, "nCmdData=%d", &iValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].nCmdData = iValue; cmd_buf_printf("OK"); return; } /* fPosition=100 */ nvals = sscanf(myarg_1, "fPosition=%lf", &fValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].position = fValue; cmd_buf_printf("OK"); return; } /* fHomePosition */ nvals = sscanf(myarg_1, "fHomePosition=%lf", &fValue); if (nvals == 1) { /* Do noting */ cmd_buf_printf("OK"); return; } /* fVelocity=20 */ nvals = sscanf(myarg_1, "fVelocity=%lf", &fValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].velocity = fValue; cmd_buf_printf("OK"); return; } /* fAcceleration=1000 */ nvals = sscanf(myarg_1, "fAcceleration=%lf", &fValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].acceleration = fValue; cmd_buf_printf("OK"); return; } /* bEnable= */ nvals = sscanf(myarg_1, "bEnable=%d", &iValue); if (nvals == 1) { setAmplifierPercent(motor_axis_no, iValue ? 100 : 0); cmd_buf_printf("OK"); return; } /* bExecute= */ nvals = sscanf(myarg_1, "bExecute=%d", &iValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].bExecute = iValue; if (!iValue) { /* bExecute=0 is always allowed, regardless the command */ motorStop(motor_axis_no); cmd_buf_printf("OK"); return; } else if (iValue == 1) { if (cmd_Motor_cmd[motor_axis_no].velocity > cmd_Motor_cmd[motor_axis_no].maximumVelocity) { fprintf(stdlog, "%s/%s:%d axis_no=%d velocity=%g maximumVelocity=%g\n", __FILE__, __FUNCTION__, __LINE__, motor_axis_no, cmd_Motor_cmd[motor_axis_no].velocity, cmd_Motor_cmd[motor_axis_no].maximumVelocity); set_nErrorId(motor_axis_no, 0x512); cmd_buf_printf("OK"); return; } switch (cmd_Motor_cmd[motor_axis_no].command_no) { case 1: { int direction = 1; if (cmd_Motor_cmd[motor_axis_no].velocity < 0) { direction = 0; cmd_Motor_cmd[motor_axis_no].velocity = -cmd_Motor_cmd[motor_axis_no].velocity; } (void)moveVelocity(motor_axis_no, direction, cmd_Motor_cmd[motor_axis_no].velocity, cmd_Motor_cmd[motor_axis_no].acceleration); cmd_buf_printf("OK"); } break; case 2: (void)movePosition(motor_axis_no, cmd_Motor_cmd[motor_axis_no].position, 1, /* int relative, */ cmd_Motor_cmd[motor_axis_no].velocity, cmd_Motor_cmd[motor_axis_no].acceleration); cmd_buf_printf("OK"); break; case 3: (void)movePosition(motor_axis_no, cmd_Motor_cmd[motor_axis_no].position, 0, /* int relative, */ cmd_Motor_cmd[motor_axis_no].velocity, cmd_Motor_cmd[motor_axis_no].acceleration); cmd_buf_printf("OK"); break; case 10: { if (cmd_Motor_cmd[motor_axis_no].homeVeloTowardsHomeSensor && cmd_Motor_cmd[motor_axis_no].homeVeloFromHomeSensor) { (void)moveHomeProc(motor_axis_no, 0, /* direction, */ cmd_Motor_cmd[motor_axis_no].nCmdData, cmd_Motor_cmd[motor_axis_no].homeVeloTowardsHomeSensor, cmd_Motor_cmd[motor_axis_no].acceleration); cmd_buf_printf("OK"); } else { cmd_buf_printf("Error : %d %g %g", 70000, cmd_Motor_cmd[motor_axis_no].homeVeloTowardsHomeSensor, cmd_Motor_cmd[motor_axis_no].homeVeloFromHomeSensor); } } break; default: RETURN_OR_DIE("%s/%s:%d line=%s command_no=%u", __FILE__, __FUNCTION__, __LINE__, myarg, cmd_Motor_cmd[motor_axis_no].command_no); } return; } RETURN_OR_DIE("%s/%s:%d line=%s invalid_iValue=%u '.'", __FILE__, __FUNCTION__, __LINE__, myarg, iValue); } /* bReset= */ nvals = sscanf(myarg_1, "bReset=%d", &iValue); if (nvals == 1) { cmd_Motor_cmd[motor_axis_no].bReset = iValue; if (iValue) { motorStop(motor_axis_no); set_nErrorId(motor_axis_no, 0); set_bError(motor_axis_no, 0); } cmd_buf_printf("OK"); return; } /* if we come here, we do not understand the command */ RETURN_OR_DIE("%s/%s:%d line=%s", __FILE__, __FUNCTION__, __LINE__, myarg); }