void turnToGoal(int pegNum){ int startHeight = 75;//initial drop height int pegDifference = 175;//each peg is same size, so the amount that it must go up should be same too int height = startHeight + (pegDifference * pegNum);//calculate height to score peg from updateEncoders(); while(leftEncoder < 500 || armLeftEncoder < height){ if(leftEncoder < 500){ motor[leftBack] = 127; motor[leftFront] = 127; motor[rightBack] = -127; motor[rightFront] = -127; }else{ motor[leftBack] = 0; motor[leftFront] = 0; motor[rightBack] = 0; motor[rightFront] = 0; } if(armLeftEncoder < height){ motor[armLeft1] = 127; motor[armLeft2] = 127; motor[armRight1] = 127; motor[armRight2] = 127; }else{ motor[armLeft1] = 0; motor[armLeft2] = 0; motor[armRight1] = 0; motor[armRight2] = 0; } updateEncoders(); } }
void turnToPeg(){ updateEncoders(); while(leftEncoder > 0 || armLeftEncoder < 0){ if(leftEncoder < 500){ motor[leftBack] = -127; motor[leftFront] = -127; motor[rightBack] = 127; motor[rightFront] = 127; }else{ motor[leftBack] = 0; motor[leftFront] = 0; motor[rightBack] = 0; motor[rightFront] = 0; } if(armLeftEncoder < 0){ motor[armLeft1] = 127; motor[armLeft2] = 127; motor[armRight1] = 127; motor[armRight2] = 127; }else{ motor[armLeft1] = 0; motor[armLeft2] = 0; motor[armRight1] = 0; motor[armRight2] = 0; } updateEncoders(); } }
void backLeft(int value){ updateEncoders(); int startV = leftEncoder; while(leftEncoder > startV-value){//1 motor[leftBack] = -speed; motor[leftFront] = -speed; updateEncoders(); } motor[leftBack] = 0; motor[leftFront] = 0; }
void backRight(int value){ updateEncoders(); int startV = rightEncoder; while(rightEncoder > -value){ motor[rightBack] = -speed; motor[rightFront] = -speed; updateEncoders(); } motor[rightBack] = 0; motor[rightFront] = 0; }
void left(int value){ updateEncoders(); int startV = rightEncoder; while(rightEncoder < startV + value){ motor[rightBack] = speed; motor[rightFront] = speed; updateEncoders(); } motor[rightBack] = 0; motor[rightFront] = 0; }
void right(int value){ updateEncoders(); int startV = leftEncoder; while(leftEncoder < startV + value){ motor[leftBack] = speed; motor[leftFront] = speed; updateEncoders(); } motor[leftBack] = 0; motor[leftFront] = 0; }
void armDown(int value){ while(armLeftEncoder > value){ motor[armLeft1] = -armSpeed; motor[armLeft2] = -armSpeed; motor[armRight1] = -armSpeed; motor[armRight2] = -armSpeed; updateEncoders(); } motor[armLeft1] = 0; motor[armLeft2] = 0; motor[armRight1] = 0; motor[armRight2] = 0; updateEncoders(); }
void armUp(int value){ while(armLeftEncoder < value){ motor[armLeft1] = armSpeed; motor[armLeft2] = armSpeed; motor[armRight1] = armSpeed; motor[armRight2] = armSpeed; updateEncoders(); } motor[armLeft1] = 0; motor[armLeft2] = 0; motor[armRight1] = 0; motor[armRight2] = 0; updateEncoders(); }
void score(){ int end = armLeftEncoder - 200; updateEncoders(); while(armLeftEncoder > end){ motor[armLeft1] = -127; motor[armLeft2] = -127; motor[armRight1] = -127; motor[armRight2] = -127; updateEncoders(); } motor[armLeft1] = 0; motor[armLeft2] = 0; motor[armRight1] = 0; motor[armRight2] = 0; nMotorEncoder[leftFront] = 0; }
void MqsConfig::onRemoveEncoder() { string user_defined_encoder_name; QList<QListWidgetItem*> selected_encoders = ui.list_encoders->selectedItems(); user_defined_encoder_name = selected_encoders.at(0)->text().toStdString(); if(user_defined_encoder_name.empty()) return; if(QMessageBox::question(this,"Confirmation","Are you really want to delete channel?",QMessageBox::Yes,QMessageBox::No) == QMessageBox::No) return; QString affected_channels(""); QSqlQuery affected_channels_result = settings->query("SELECT name FROM channel WHERE encoder='%s'", user_defined_encoder_name.c_str()); do { QSqlRecord affected_channel = affected_channels_result.record(); affected_channels += affected_channel.value("name").toString(); }while(affected_channels_result.next()); if(!affected_channels.isEmpty()) { QString question("Next linked channels: " + affected_channels + " will be deleted too. Continue?"); if(QMessageBox::question(this,"Channel dependencies found", question, QMessageBox::Yes,QMessageBox::No) == QMessageBox::No) return; } settings->query("DELETE FROM channel WHERE encoder='%s'", user_defined_encoder_name.c_str()); settings->query("DELETE FROM encoder WHERE name = '%s'", user_defined_encoder_name.c_str()); updateEncoders(); updateChannels(); }
void dropToPeg(){ while(armLeftEncoder > 0){ motor[armLeft1] = 127; motor[armLeft2] = 127; motor[armRight1] = 127; motor[armRight2] = 127; updateEncoders(); } motor[armLeft1] = 0; motor[armLeft2] = 0; motor[armRight1] = 0; motor[armRight2] = 0; }
void backward(int value){ while(rightEncoder > -value){ motor[rightBack] = -speed; motor[rightFront] = -speed; motor[leftBack] = -speed; motor[leftFront] = -speed; updateEncoders(); } motor[rightBack] = 0; motor[rightFront] = 0; motor[leftBack] = 0; motor[leftFront] = 0; SensorValue[rightEncoder] = 0; SensorValue[leftEncoder] = 0; }
MqsConfig::MqsConfig(QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags) { ui.setupUi(this); updateEncoders(); updateChannels(); updateResolutions(); vector<string> suported_channels = ChannelManager::getSuportedPlugins(); for(unsigned int i = 0; i < suported_channels.size(); ++i) { QAction* act = new QAction(suported_channels[i].c_str(), 0); add_channel_menu.addAction(act); connect(act, SIGNAL(triggered()), this, SLOT(onCreateChannel())); } QSqlRecord plugin_path_rec = settings->query("SELECT value as plugin_path FROM property WHERE name = 'plugin_path'").record(); QSqlRecord screen_shot_path_rec = settings->query("SELECT value as screen_shot_path FROM property WHERE name = 'screen_shot_path'").record(); ui.line_plugin_path->setText(plugin_path_rec.value("plugin_path").toString()); ui.line_screen_shot_path->setText(screen_shot_path_rec.value("screen_shot_path").toString()); QObject::connect(this, SIGNAL(updateMain(GUIUpdate)), parent, SLOT(updateMain(GUIUpdate))); QObject::connect(ui.button_add_channel, SIGNAL(clicked()), this, SLOT(onAddChannel())); QObject::connect(ui.button_edit_channel, SIGNAL(clicked()), this, SLOT(onEditChannel())); QObject::connect(ui.button_remove_channel, SIGNAL(clicked()), this, SLOT(onRemoveChannel())); QObject::connect(ui.button_add_encoder, SIGNAL(clicked()), this, SLOT(onAddEncoder())); QObject::connect(ui.button_edit_encoder, SIGNAL(clicked()), this, SLOT(onEditEncoder())); QObject::connect(ui.button_remove_encoder, SIGNAL(clicked()), this, SLOT(onRemoveEncoder())); QObject::connect(ui.list_resolutions, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(onResolutionItemChanged(QListWidgetItem *))); QObject::connect(ui.button_clearall_resolutions, SIGNAL(clicked()), this, SLOT(onClearAllResolutions())); QObject::connect(ui.button_sellectall_resolutions, SIGNAL(clicked()), this, SLOT(onSellectAllResolutions())); QObject::connect(ui.button_loaddefaults_resolutions, SIGNAL(clicked()), this, SLOT(onLoadDefaultResolutions())); QObject::connect(ui.button_add_resolutions, SIGNAL(clicked()), this, SLOT(onAddResolutions())); QObject::connect(ui.button_remove_resolutions, SIGNAL(clicked()), this, SLOT(onRemoveResolutions())); QObject::connect(ui.button_edit_resolutions, SIGNAL(clicked()), this, SLOT(onEditResolutions())); QObject::connect(ui.line_screen_shot_path, SIGNAL(textChanged(const QString &)), this, SLOT(onEditScreenShotPath(const QString &))); QObject::connect(ui.line_plugin_path, SIGNAL(textChanged(const QString &)), this, SLOT(onEditPluginPath(const QString &))); QObject::connect(ui.select_plugins_dir, SIGNAL(clicked()), this, SLOT(onSelectPluginPath())); QObject::connect(ui.select_screenshot_dir, SIGNAL(clicked()), this, SLOT(onSelectScreenShotPath())); QObject::connect(ui.list_encoders, SIGNAL(currentTextChanged(const QString &)), this, SLOT(onEncoderSelect(const QString &))); }
int main() { CURL *curl; CURLcode res; wiringPiSetup () ; /*using pins 23/24*/ struct encoder *encoder = setupencoder(4,5,6); int buttonState; long value; char buffer[250]; while (1) { updateEncoders(); buttonState = digitalRead(6); long l = encoder->value; if(l!=value) { printf("value: %d\n", (void *)l); curl=curl_easy_init(); sprintf(buffer, "http://127.0.0.1/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"Application.SetVolume\",\"params\":{\"volume\":%d},\"id\":1}", l); curl_easy_setopt(curl, CURLOPT_URL, buffer); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); } /* always cleanup */ curl_easy_cleanup(curl); value = l; } if(buttonState==1) { curl=curl_easy_init(); sprintf(buffer, "http://127.0.0.1/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"params\":{\"playerid\":0},\"id\":1}"); curl_easy_setopt(curl, CURLOPT_URL, buffer); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); printf("Button pushed!\n"); delay(1); } } return(0); }
int main(int argc, char **argv) { ros::init(argc, argv, "talker"); ros::NodeHandle n; ros::Publisher pub = n.advertise<pi_rotary_encoder::ParamUpdate>("parameter_update", 1000); ros::Rate loop_rate(10); //int r = wiringPiSetup(); int r = wiringPiSetup(); revokeRoot(); printf("setup: %d\n", r); // wiringPiSetup requires sudo, wiringPiSetupSys requires you add this to your /etc/rc.local: // // for example, to use pin 23 as an input: // // gpio export 23 in // struct encoder *encoder = setupencoder(4,5); long value; while (ros::ok()) { updateEncoders(); long l = encoder->value; if (l!=value) { printf("value: %d\n", (void *)l); value = l; pi_rotary_encoder::ParamUpdate msg; msg.parameter = "shutter_speed"; msg.value = value*10; pub.publish(msg); } ros::spinOnce(); loop_rate.sleep(); } }
/******************************************************************************* *Função principal do controle de velocidade ----------------------------------- */ void controleVelocidade(void) { updateEncoders(); // Updates the distance and speeds controladorPID(); // Speed controller }