// time is in milliseconds
// distance is in tenths of inches
// direction is 1 or -1 -- positive is forwards
void moveStraight(int direction, int time, int driveTarget)
{
	nMotorEncoder[LeftMWheel] = 0;
	int distance = 0;
	float pwr = 0;
	while(distance < driveTarget )
	{
		distance = abs(nMotorEncoder[LeftMWheel]);
		// works
		if( distance <= driveTarget / 2)
			pwr = distance / 5 + 20; //TODO: figure out how this works
		else
			pwr = ( driveTarget - distance ) / 10 + 20;

		// test old formula
		//pwr = oldPwr(driveTarget, distance);
		// test new formula
		//pwr = newPwr(driveTarget, distance);

		pwr *= direction;
		setLeft(pwr);
		setRight(pwr);
	} // end while loop

	setLeft(0);
	setRight(0);
}
	void rampDrive(int driveTarget)
	{
		int direction = 1;
		if( driveTarget < 0 )
		{
			direction = -1;
			driveTarget *= -1;
		}
		nMotorEncoder[LeftMWheel] = 0;
		int distance = 0;
		int pwr = 0;
		while(distance < driveTarget )
		{
			//distance = abs ( nMotorEncoder[leftBack] + nMotorEncoder[rightBack] ) / 2;

			distance = abs(nMotorEncoder[LeftMWheel]);

			if( distance <= driveTarget / 2)
				pwr = distance / 5 + 20;
			else
				pwr = ( driveTarget - distance ) / 10 + 20;

			pwr *= direction;
			setLeft(pwr);
			setRight(pwr);
		}
		setLeft(0);
		setRight(0);
	}
	// time is in milliseconds
	// distance is in tenths of inches
	// direction is 1 or -1 -- positive is forwards
	void moveStraight(int direction, int time, int driveTarget)
	{
		nMotorEncoder[LeftMWheel] = 0;
		int distance = 0;
		float pwr = 0;
			while(distance < driveTarget )
			{

					distance = abs(nMotorEncoder[LeftMWheel]);
					//initial version
					//pwr = 64 * sin(distance * PI / driveTarget);
					//improved version

					//SHITTY PID:
					//pwr = 0.05 * (driveTarget - distance) + 0.0003 * (0.05 * (driveTarget * distance - 0.5 * (distance * distance)));

					if( distance <= driveTarget / 2)
						pwr = distance / 5 + 20; //TODO: figure out how this works
					else
						pwr = ( driveTarget - distance ) / 10 + 20;

						//pwr = -1 * (1.11 * sqrt(driveTarget) - 10) * cos(distance * 2 * PI / driveTarget) + (1.11 * sqrt(distance)) + 10;


					pwr *= direction;
					setLeft(pwr);
					setRight(pwr);
			}
			setLeft(0);
			setRight(0);
		}
Esempio n. 4
0
 void PlayerInputStruct::fromGameEvent(const GameControl &control, bool state)
 {
     switch(control)
     {
         case GameControl::ACTION:
             setAction(state);
             break;
         case GameControl::UP:
             if(state)
                 setUp(100000);
             else
                 setUp(0);
             break;
         case GameControl::DOWN:
             if(state)
                 setDown(100000);
             else
                 setDown(0);
             break;
         case GameControl::LEFT:
             if(state)
                 setLeft(100000);
             else
                 setLeft(0);
             break;
         case GameControl::RIGHT:
             if(state)
                 setRight(100000);
             else
                 setRight(0);
             break;
         case GameControl::BUTTON1:
             setButton1(state);
             break;
         case GameControl::BUTTON2:
             setButton2(state);
             break;
         case GameControl::BUTTON3:
             setButton3(state);
             break;
         case GameControl::BUTTON4:
             setButton4(state);
             break;
         case GameControl::BUTTON5:
             setButton5(state);
             break;
         case GameControl::BUTTON6:
             setButton6(state);
             break;
         default:
             //Nothing to do; control is not handled by the automatic conversion.
             break;
     }
 }
		void pickUpBall(int goals)
	{
		resetValues(0);
		intake(1);
		wait10Msec(30);
		int current = 0;
		while(current < goals * 250)
		{
			setLeft(25); setRight(25);
			current = nMotorEncoder[LeftMWheel];
		}
		intake(0);
		setLeft(0); setRight(0);
	}
void blueUdit()
{
	deploy();
	intake(1);
	wait10Msec(10);
	moveStraight(1, 0, 475); //picks up
	wait10Msec(50);
	moveStraight(-1, 0, 475);//comes back
	//intake(0)();
	spin(1, 0, 400);
	lift(BUMP);
	holdArm();
	waitForButton();
	intake(-1);
	wait10Msec(100);
	resetValues(0);
	liftDown(); // added

	waitForButton();
	//liftDown();
	// end Devansh
	//waitForButton();
	intake(1);
	moveStraight(1, 0, (HALF_TILE));
	wait10Msec(50);
	pickUpBall(1);
	spin(1, 0, 200);
	//crossBump();
	lift(BUMP);
	nMotorEncoder[LeftMWheel] = 0;
	if(true)
	{
		setRight(127);
		wait10Msec(10);
		setLeft(127);
	}
	while (abs(nMotorEncoder[LeftMWheel]) < 500)
	{
		setRight(127); setLeft(127);
	}
	setRight(0); setLeft(0);
	lift(BARRIER);
	holdArm();
	wait10Msec(30);
	moveStraight(1, 0, 550);
	intake(-1);
	// end udit
	resetValues(1000);
}
Snake::Snake():AnimUT()
{
#ifdef debug
    qDebug("Snake launched");
#endif

    controls->addAnimationControl(animate, 200);

    cellSize = 15;
    nbCells = 20;

    // controls
    snakeItem = new SnakeItem(cellSize, nbCells);

    controls->addLabel("Movements");
    QPushButton *upBtn = controls->addButton("Up");
    connect(upBtn, SIGNAL(released()), snakeItem, SLOT(setUp()));
    QPushButton *downBtn = controls->addButton("Down");
    connect(downBtn, SIGNAL(released()), snakeItem, SLOT(setDown()));
    QPushButton *leftBtn = controls->addButton("Left");
    connect(leftBtn, SIGNAL(released()), snakeItem, SLOT(setLeft()));
    QPushButton *rightBtn = controls->addButton("Right");
    connect(rightBtn, SIGNAL(released()), snakeItem, SLOT(setRight()));

    controls->addDivider();

    score = controls->addLabel("Score : 0");
    connect(snakeItem, SIGNAL(updateScore(int)), this, SLOT(updateScore(int)));

    // viewer
    drawBorders();
    viewer->addItem(snakeItem);
}
Esempio n. 8
0
bool AnchorsBase::setAnchor(const Qt::AnchorPoint &p, QWidget *target, const Qt::AnchorPoint &point)
{
    if (!target) {
        return false;
    }

    AnchorsBase *base = AnchorsBasePrivate::getWidgetAnchorsBase(target);

    if (!base) {
        base = new AnchorsBase(target);
    }

    const AnchorInfo *info = base->d_func()->getInfoByPoint(point);

    switch (p) {
    case Qt::AnchorTop:
        return setTop(info);
    case Qt::AnchorBottom:
        return setBottom(info);
    case Qt::AnchorLeft:
        return setLeft(info);
    case Qt::AnchorRight:
        return setRight(info);
    case Qt::AnchorHorizontalCenter:
        return setHorizontalCenter(info);
    case Qt::AnchorVerticalCenter:
        return setVerticalCenter(info);
    default:
        return false;
    }
}
Esempio n. 9
0
    PixelRegion PixelRegion::globalCut(Side side, int p) {
        if (!lineIntersect(side, p)) {
            return PixelRegion({ 0, 0 }, { 0, 0 });
        }

        PixelRegion cutOff(*this);
        int cutSize = 0;
        switch (side) {
        case LEFT:
            setLeft(p);
            cutOff.setRight(p - cutSize);
            break;
        case TOP:
            setTop(p);
            cutOff.setBottom(p - cutSize);
            break;
        case RIGHT:
            setRight(p);
            cutOff.setLeft(p + cutSize);
            break;
        case BOTTOM:
            setBottom(p);
            cutOff.setTop(p + cutSize);
            break;
        }
        return cutOff;
    }
Esempio n. 10
0
void GuiSetBorder::mousePressEvent(QMouseEvent * e)
{
	if (e->y() > e->x()) {
		if (e->y() < height() - e->x()) {
			if (left_.enabled) {
				setLeft(!left_.set);
				// emit signal
				leftSet(left_.set);
			}
		} else {
			if (bottom_.enabled) {
				setBottom(!bottom_.set);
				// emit signal
				bottomSet(bottom_.set);
			}
		}
	} else {
		if (e->y() < height() - e->x()) {
			if (top_.enabled) {
				setTop(!top_.set);
				// emit signal
				topSet(top_.set);
			}
		} else {
			if (right_.enabled) {
				setRight(!right_.set);
				// emit signal
				rightSet(right_.set);
			}
		}
	}
	update();
	// emit signal
	clicked();
}
Esempio n. 11
0
void Rect::expand( const QPoint& point )
{
	setLeft  ( qMin(point.x(), left()  ) );
	setRight ( qMax(point.x(), right() ) );
	setTop   ( qMax(point.y(), top()   ) );
	setBottom( qMin(point.y(), bottom()) ); 
};
void SettingsPageComponent::resized() {
  auto bounds = getLocalBounds();
  int numRows = 4;
  double rowProp = 0.6/numRows;
  {
    for (int i = 0, j = 0; i < numRows; ++i) {
      if (i > 0) verticalLayout.setItemLayout(j++, 0, -1, -1);
      verticalLayout.setItemLayout(j++, -rowProp, -rowProp, -rowProp);
    }

    Component *settingsItems[] = {
      wifiCategoryItem, nullptr,
      screenBrightnessSlider, nullptr,
      volumeSlider, nullptr,
      advanced
    };
    int numItems = sizeof(settingsItems) / sizeof(Component*);
    
    auto b = bounds;
    b.setLeft(60);
    b.setTop(30);
    b.setHeight(b.getHeight() - 30);
    b.setWidth(b.getWidth() - 60);
    verticalLayout.layOutComponents(settingsItems, numItems, b.getX(), b.getY(), b.getWidth(),
                                    b.getHeight(), true, true);
  }

  mainPage->setBounds(bounds);

  backButton->setBounds(bounds.getX(), bounds.getY(), 60, bounds.getHeight());
}
Esempio n. 13
0
static RenderStyle createFullScreenStyle()
{
    auto fullscreenStyle = RenderStyle::create();

    // Create a stacking context:
    fullscreenStyle.setZIndex(INT_MAX);

    fullscreenStyle.setFontDescription({ });
    fullscreenStyle.fontCascade().update(nullptr);

    fullscreenStyle.setDisplay(FLEX);
    fullscreenStyle.setJustifyContentPosition(ContentPositionCenter);
    fullscreenStyle.setAlignItemsPosition(ItemPositionCenter);
    fullscreenStyle.setFlexDirection(FlowColumn);
    
    fullscreenStyle.setPosition(FixedPosition);
    fullscreenStyle.setWidth(Length(100.0, Percent));
    fullscreenStyle.setHeight(Length(100.0, Percent));
    fullscreenStyle.setLeft(Length(0, WebCore::Fixed));
    fullscreenStyle.setTop(Length(0, WebCore::Fixed));
    
    fullscreenStyle.setBackgroundColor(Color::black);

    return fullscreenStyle;
}
Esempio n. 14
0
task usercontrol()
{

	// Flags

	// Servo / program initialization:

	zeroEncoders();

	// Main loop:

	waitForStart();

	while (true)
	{

		getJoystickSettings(joystick);

		setLeft(100);
		setRight(100);

	}

	return;

}
Esempio n. 15
0
BPlusNode::BPlusNode(IXFileHdr &hdr, PFPageHandle &page, bool load)
	: len_(hdr.len)
	, type_(hdr.type)
	, capacity_(hdr.capacity)
	, page_(page)
{
	// allocPage 用于表示这个页面是否为新分配的
	// 布局如下
	//  一共n个key,占据 n * len_字节的大小
	//  一共n个rid,占据 n * sizeof(RID) 字节的大小
	//  一个字节用于记录一共有多少个key,占据sizeof(numOfKeys_)字节的大小
	//  一个left字段,占据sizeof(Page)字节的大小
	//  一个right字段,占据了sizeof(Page)字节的大小
	Ptr addr = page.rawPtr();
	num_ = page.page();

	keys_ = addr;
	rids_ = reinterpret_cast<RID *>(addr + len_ * capacity_);
	if (load) { // 说明这个页面实际上已经初始化过了
		size_ = size();
		left_ = left();
		right_ = right();
	}
	else { // 这里需要重新初始化
		size_ = 0;
		setSize(0);
		setLeft(-1);
		setRight(-1);
		page.setDirty();
	}
}
Esempio n. 16
0
void GfxCropDialog::bindEvents()
{
	// Left text box
	text_left_->Bind(wxEVT_TEXT_ENTER, &GfxCropDialog::onTextEnter, this);
	text_left_->Bind(wxEVT_KILL_FOCUS, [&](wxFocusEvent& e) {
		setLeft();
		e.Skip();
	});

	// Top text box
	text_top_->Bind(wxEVT_TEXT_ENTER, &GfxCropDialog::onTextEnter, this);
	text_top_->Bind(wxEVT_KILL_FOCUS, [&](wxFocusEvent& e) {
		setTop();
		e.Skip();
	});

	// Right text box
	text_right_->Bind(wxEVT_TEXT_ENTER, &GfxCropDialog::onTextEnter, this);
	text_right_->Bind(wxEVT_KILL_FOCUS, [&](wxFocusEvent& e) {
		setRight();
		e.Skip();
	});

	// Bottom text box
	text_bottom_->Bind(wxEVT_TEXT_ENTER, &GfxCropDialog::onTextEnter, this);
	text_bottom_->Bind(wxEVT_KILL_FOCUS, [&](wxFocusEvent& e) {
		setBottom();
		e.Skip();
	});

	// Absolute/Relative radio buttons
	rb_absolute_->Bind(wxEVT_RADIOBUTTON, [&](wxCommandEvent&) { updateValues(); });
	rb_relative_->Bind(wxEVT_RADIOBUTTON, [&](wxCommandEvent&) { updateValues(); });
}
Esempio n. 17
0
void GuiSetBorder::setAll(bool border)
{
	setLeft(border);
	setRight(border);
	setTop(border);
	setBottom(border);
}
Esempio n. 18
0
void buildBinaryTree(pin_node root, int i)
{
	int v;
	pin_node q, p;
	p = q = root;
	while (q) {
		p = q;
		v = info(p);
		if (v == i) {
			printf("duplicate\n");
			q = NULL;
		} else if (v < i) {
			q = q->left;

		} else {
			q = q->right;
		}
		

	}

	if (p) {
		int v = p->val;
		 if (v < i) {
		 	setLeft(p, i);
		} else {
			setRight(p, i);
		}
	}
	
}
Esempio n. 19
0
	int MailTreeDelegate::DrawMessageActionIcons (QPainter *painter,
			const QStyleOptionViewItem& option, const QModelIndex& index, int height) const
	{
		if (Mode_ != MailListMode::Normal)
			return 0;

		if (option.state & QStyle::State_MouseOver)
			return 0;

		const auto& actionsVar = index.data (MailModel::MailRole::MessageActions);
		if (actionsVar.isNull ())
			return 0;

		auto actionInfos = actionsVar.value<QList<MessageListActionInfo>> ();
		if (actionInfos.isEmpty ())
			return 0;

		std::reverse (actionInfos.begin (), actionInfos.end ());

		if (ActionsHintsBalls_)
			height -= Padding * 2;

		painter->save ();
		painter->setRenderHint (QPainter::Antialiasing);

		painter->setPen (Qt::NoPen);

		auto rect = option.rect;
		rect.setLeft (rect.right () - height - Padding);
		rect.setSize ({ height, height });
		rect.moveTop (rect.top () + Padding);
		for (const auto& item : actionInfos)
		{
			if (item.Flags_ & MessageListActionFlag::AlwaysPresent)
				continue;

			if (ActionsHintsBalls_)
			{
				QRadialGradient gradient;
				gradient.setCoordinateMode (QGradient::ObjectBoundingMode);
				gradient.setFocalPoint ({ 0.3, 0.3 });
				gradient.setCenter ({ 0.5, 0.5 });
				gradient.setRadius (0.5);
				gradient.setColorAt (0, item.ReprColor_.lighter (200));
				gradient.setColorAt (1, item.ReprColor_.darker (120));

				painter->setBrush (gradient);
				painter->drawEllipse (rect);
			}
			else
				item.Icon_.paint (painter, rect);

			rect.moveLeft (rect.left () - height - Padding);
		}

		painter->restore ();

		return option.rect.right () - rect.right ();
	}
Esempio n. 20
0
 void PixelRegion::setSide(Side side, int pos) {
     switch (side) {
     case LEFT: setLeft(pos); break;
     case TOP: setTop(pos); break;
     case RIGHT: setRight(pos); break;
     case BOTTOM: setBottom(pos); break;
     }
 }
// -1 is max left
// 0 is max forward
// 1 is max right
void MotorController::arc(double direction, double speedScale) {
    if (abs(direction) > 1)direction /= abs(direction); //makes direction between 1 & -1
    printf("Direction: %f\n", direction);

    if (direction < 0) { //left
        setLeft((int) (LEFT_MAX * (1 - abs((int) direction)) *
                       speedScale));    //sets the left motor to something less than the max speed
        setRight((int) (RIGHT_MAX * (speedScale - 0.05)));                        //sets the right motor to max speed
    } else if (direction > 0) { //right
        setLeft((int) (LEFT_MAX * speedScale));                        //sets the left motor the max speed
        setRight((int) (RIGHT_MAX * (1 - direction) *
                        speedScale));     //sets the right motor to something less than the max speed
    } else if (direction == 0) {
        moveForward();
    }

}
Esempio n. 22
0
OOModel::Expression* AssignmentDescriptor::create(const QList<OOModel::Expression*>& operands)
{
	auto ae = new OOModel::AssignmentExpression();
	ae->setOp(assignmentType_);
	ae->setLeft(operands.first());
	ae->setRight(operands.last());
	return ae;
}
Esempio n. 23
0
struct tree *createTree(int data, struct tree *left, struct tree *right) {
    struct tree *structtree = malloc(sizeof(struct tree));
    assert(structtree!=NULL); //check to make sure structtree exist
    structtree->value = data; //give value to the tree
    structtree->parent = NULL; //set parent
    setLeft(structtree, left); //set child
    setRight(structtree, right); //set child
    return structtree;
}
Esempio n. 24
0
QRectF ScriptEditorItem::boundingRect() const
{
    auto br = QGraphicsTextItem::boundingRect();
    br.setBottom(br.bottom() + border);
    br.setTop(br.top() - border);
    br.setLeft(br.left() - border);
    br.setRight(br.right() + border);
    return br;
}
Esempio n. 25
0
void setTemp()
{
	//initalises temp, get sensor readings and sets the local temp to a normalised neural vector
  clearTemp();
	setLeft();
	setCentre();
	setRight();
	normaliseTemp();
}
Esempio n. 26
0
void PlayerInputAbs::swapSides()
{
	bool left = mFlags & F_LEFT;
	bool right = mFlags & F_RIGHT;

	setLeft(right);
	setRight(left);

	mTarget = RIGHT_PLANE - mTarget;
}
	void Udit()
	{
		deploy();
		intake(true);
		moveStraight(1, 0, 150);
		wait10Msec(30);
		moveStraight(-1, 0, 150);
		lift(BUMP);
		moveStraight(-1, 0, 150);
		setRight(127); setLeft(127);
	}
Esempio n. 28
0
// -----------------------------------------------------------------------------
// Called when enter is pressed in a text box
// -----------------------------------------------------------------------------
void GfxCropDialog::onTextEnter(wxCommandEvent& e)
{
	if (e.GetEventObject() == text_left_)
		setLeft();
	else if (e.GetEventObject() == text_top_)
		setTop();
	else if (e.GetEventObject() == text_right_)
		setRight();
	else if (e.GetEventObject() == text_bottom_)
		setBottom();
}
Esempio n. 29
0
static struct tree *insert(struct tree *root, int x)
{
    if (root == NULL)
	root = createTree(x, NULL, NULL);
    else if (x < getData(root))
	setLeft(root, insert(getLeft(root), x));
    else
	setRight(root, insert(getRight(root), x));

    return root;
}
Esempio n. 30
0
//----Gets local view and processes ready for comparison----//
void setTemp()
{
	//initalises temp, get sensor readings and sets the local temp to a normalised neural vector
  clearTemp();
	float rightSonarValue = SensorValue(rightSonar); //obvious
  float leftSonarValue = SensorValue(leftSonar);
  float centreSonarValue = SensorValue(centreSonar);
  setLeft(leftSonarValue);
	setCentre(centreSonarValue);
	setRight(rightSonarValue);
	normaliseTemp();
}