void SkyPointer::init(void) {
    // Enable pin
    pinMode(ENABLE, OUTPUT);
    digitalWrite(ENABLE, LOW);
    // Configure outputs
    pinMode(XSTEP, OUTPUT);
    pinMode(XDIR, OUTPUT);
    pinMode(YSTEP, OUTPUT);
    pinMode(YDIR, OUTPUT);
    // Photo diode pin
    pinMode(PHOTO_PIN, INPUT);
    // Laser pin
    pinMode(LASER_PIN, OUTPUT);

    // Switch laser off at start
    laser(false);

    // Configure axes logic and dinamics
    azMotor.setPinsInverted(false, false, true);
    azMotor.setAcceleration(ACCEL);
    azMotor.setEnablePin(ENABLE);

    altMotor.setPinsInverted(true, false, true);
    altMotor.setAcceleration(ACCEL);
    altMotor.setEnablePin(ENABLE);
}
void SkyPointer::move(int16_t az, int16_t alt) {
    digitalWrite(ENABLE, LOW);
    azMotor.setMaxSpeed(MOVE_SPEED);
    altMotor.setMaxSpeed(MOVE_SPEED);
    azMotor.move(az);
    altMotor.move(alt);
    laser(true);
}
Exemplo n.º 3
0
void BreLaser::render(sf::RenderTarget& window)
{
    sf::RectangleShape laser(sf::Vector2f(6, 240));
    laser.setOrigin(3, 0);
    laser.setFillColor(sf::Color(255,0,0,192));
    laser.setRotation(getRotation());
    laser.setPosition(getPosition());
    window.draw(laser);
}
Exemplo n.º 4
0
int main() 
{

  int i;

  history_file = fopen("hist.data", "w");

  init();			/* do initialisation */
  loadx();			/* load particles onto grid */
  particle_bc();		/* particle boundary conditions */
                     
  loadv();			/* define velocity distribution */

  density();			/* compute initial density from particles */
  add_neutral();                   /* background ion density */
  laser();                      /* initialise laser field */
  field();			/* compute initial electric field */

  diagnostics();		/* output initial conditions */

 
  for (itime=1; itime<=ntrun; itime++) 
    {

      push();			/* Push particles */
      particle_bc();		/* particle boundary conditions */

      density();		/* compute density */

      laser();                  /* update laser field */
      field();		        /* compute electric field (Poisson) */

      diagnostics();		/* output snapshots and time-histories */

    }


  close(history_file);          /*   close time-hist files */


}
Exemplo n.º 5
0
void PlayerBonusLaser::render(sf::RenderTarget& window)
{
    sf::RectangleShape laser(sf::Vector2f(6, length));
    laser.setOrigin(3, length);
    if (type == 1)
        laser.setFillColor(sf::Color(24, 161, 212,128));
    else
        laser.setFillColor(sf::Color(231, 24, 118,128));
    laser.setPosition(getPosition());
    laser.setRotation(getRotation());
    window.draw(laser);
}
void SkyPointer::run() {
    azMotor.run();
    altMotor.run();

    if (isLaserOn()) {
        // Switch off the laser if timeout has been reached
        if (millis() - laserOnTime > laserTimeout) {
            laser(false);
        }
    } else if (!homing) {
        // Switch on the laser if the motors are running
        if (azMotor.isRunning() || (altMotor.isRunning())) {
            laser(true);
        }
    }

    if (homing && digitalRead(PHOTO_PIN)) {
        altMotor.stop();
        altMotor.setCurrentPosition(0);
        homing = false;
    }
}
Exemplo n.º 7
0
void Data::parse(char sensor, double data[]){
    switch (sensor){
        case 'O':
        {
            Odom odom(data);
            this->odoms.push_back(&odom);
            break;
        }
        case 'L':
        {
            Laser laser(data);
            this->lasers.push_back(&laser);
            break;
        }
    }
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
	ros::init(argc, argv, "neato_laser_publisher");
	if( ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug) ) {
		ros::console::notifyLoggerLevelsChanged();
	}
	ros::NodeHandle n;
	ros::NodeHandle priv_nh("~");

	std::string port;
	int baud_rate;
	std::string frame_id;
	int firmware_number;

	std_msgs::UInt16 rpms; 

	priv_nh.param("port", port, std::string("/dev/ttyUSB0"));
	priv_nh.param("baud_rate", baud_rate, 115200);
	priv_nh.param("frame_id", frame_id, std::string("neato_laser"));
	priv_nh.param("firmware_version", firmware_number, 2);//default to the new firmware

	boost::asio::io_service io;

	try {
		xv_11_laser_driver::XV11Laser laser(port, baud_rate, firmware_number, io);
		ros::Publisher laser_pub = n.advertise<sensor_msgs::LaserScan>("scan", 1000);
		ros::Publisher motor_pub = n.advertise<std_msgs::UInt16>("rpms",1000);

		ROS_DEBUG("Running XV-11 lidar publisher");
		while (ros::ok()) {
			sensor_msgs::LaserScan::Ptr scan(new sensor_msgs::LaserScan);
			scan->header.frame_id = frame_id;
			scan->header.stamp = ros::Time::now();
			laser.poll(scan);
			rpms.data=laser.rpms;
			laser_pub.publish(scan);
			motor_pub.publish(rpms);

		}
		laser.close();
		return 0;
	} catch (boost::system::system_error ex) {
		ROS_DEBUG("stopping...");
		ROS_ERROR("Error instantiating laser object. Are you sure you have the correct port and baud rate? Error was %s", ex.what());
		return -1;
	}
}
int main(int argc, char **argv)
{
  ros::init(argc, argv, "neato_laser_publisher");
  ros::NodeHandle n;
  ros::NodeHandle priv_nh("~");

  std::string port;
  int baud_rate;
  std::string frame_id;
  int firmware_number;
 
  std_msgs::UInt16 rpms; 

  priv_nh.param("port", port, std::string("/dev/xv11"));
  priv_nh.param("baud_rate", baud_rate, 115200);
  //priv_nh.param("frame_id", frame_id, std::string("neato_laser"));
  priv_nh.param("frame_id", frame_id, std::string("xv11"));
  priv_nh.param("firmware_version", firmware_number, 2);

  boost::asio::io_service io;

  try {
    xv_11_laser_driver::XV11Laser laser(port, baud_rate, firmware_number, io);
    ros::Publisher laser_pub = n.advertise<sensor_msgs::LaserScan>("scan", 1000);
    //ros::Publisher laser_pub = n.advertise<sensor_msgs::LaserScan>("xv11_scan", 1000);
    ros::Publisher motor_pub = n.advertise<std_msgs::UInt16>("rpms",1000);

    while (ros::ok()) {
      sensor_msgs::LaserScan::Ptr scan(new sensor_msgs::LaserScan);
      scan->header.frame_id = frame_id;
      scan->header.stamp = ros::Time::now();
      laser.poll(scan);
      rpms.data=laser.rpms;
      laser_pub.publish(scan);
      motor_pub.publish(rpms);

    }
    laser.close();
    return 0;
  } catch (boost::system::system_error ex) {
    ROS_ERROR("Error instantiating laser object. Are you sure you have the correct port and baud rate? Error was %s", ex.what());
    return -1;
  }
}
int main(int argc, char** argv) {
    
    ros::init(argc, argv, "laser_2_pointcloud");
    ros::NodeHandle node;

    std::string base_tf;
    std::string laser_topic;

    node.param("/laser_to_pointcloud/base_tf", base_tf, std::string("/odom"));
    node.param("/laser_to_pointcloud/laser_topic", laser_topic, std::string("/base_scan"));

    LaserScanReceiver laser(node, base_tf, laser_topic);
    
    ros::Rate loop_rate(10);
    while (node.ok()) {
		ros::spinOnce();
		loop_rate.sleep();
    }
    
}
Exemplo n.º 11
0
void SkyPointer::goTo(uint16_t az, uint16_t alt) {
    int16_t delta;
    uint16_t pos;

    digitalWrite(ENABLE, LOW);
    azMotor.setMaxSpeed(GOTO_SPEED);
    altMotor.setMaxSpeed(GOTO_SPEED);

    // AZ motor
    az = MOD(az, USTEPS_REV);
    pos = MOD(azMotor.currentPosition(), USTEPS_REV);
    delta = calcSteps(pos, az);
    azMotor.move(delta);

    // ALT motor
    alt = MOD(alt, USTEPS_REV);
    pos = MOD(altMotor.currentPosition(), USTEPS_REV);
    delta = calcSteps(pos, alt);
    altMotor.move(delta);
    laser(true);
}
Exemplo n.º 12
0
int main(int argc, char** argv)
{
  // Initialize some global data
  Aria::init();

  // If you want ArLog to print "Verbose" level messages uncomment this:
  //ArLog::init(ArLog::StdOut, ArLog::Verbose);

  // This object parses program options from the command line
  ArArgumentParser parser(&argc, argv);

  // Load some default values for command line arguments from /etc/Aria.args
  // (Linux) or the ARIAARGS environment variable.
  parser.loadDefaultArguments();

  // Central object that is an interface to the robot and its integrated
  // devices, and which manages control of the robot by the rest of the program.
  ArRobot robot;

  // Object that connects to the robot or simulator using program options
  ArRobotConnector robotConnector(&parser, &robot);

  // If the robot has an Analog Gyro, this object will activate it, and 
  // if the robot does not automatically use the gyro to correct heading,
  // this object reads data from it and corrects the pose in ArRobot
  ArAnalogGyro gyro(&robot);

  // Connect to the robot, get some initial data from it such as type and name,
  // and then load parameter files for this robot.
  if (!robotConnector.connectRobot())
  {
    // Error connecting:
    // if the user gave the -help argumentp, then just print out what happened,
    // and continue so options can be displayed later.
    if (!parser.checkHelpAndWarnUnparsed())
    {
      ArLog::log(ArLog::Terse, "Could not connect to robot, will not have parameter file so options displayed later may not include everything");
    }
    // otherwise abort
    else
    {
      ArLog::log(ArLog::Terse, "Error, could not connect to robot.");
      Aria::logOptions();
      Aria::exit(1);
    }
  }

  // Connector for laser rangefinders
  ArLaserConnector laserConnector(&parser, &robot, &robotConnector);

  // Connector for compasses
  ArCompassConnector compassConnector(&parser);

  // Parse the command line options. Fail and print the help message if the parsing fails
  // or if the help was requested with the -help option
  if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
  {    
    Aria::logOptions();
    exit(1);
  }

  // Used to access and process sonar range data
  ArSonarDevice sonarDev;
  
  // Used to perform actions when keyboard keys are pressed
  ArKeyHandler keyHandler;
  Aria::setKeyHandler(&keyHandler);

  // ArRobot contains an exit action for the Escape key. It also 
  // stores a pointer to the keyhandler so that other parts of the program can
  // use the same keyhandler.
  robot.attachKeyHandler(&keyHandler);
  printf("You may press escape to exit\n");

  // Attach sonarDev to the robot so it gets data from it.
  robot.addRangeDevice(&sonarDev);

  
  // Start the robot task loop running in a new background thread. The 'true' argument means if it loses
  // connection the task loop stops and the thread exits.
  robot.runAsync(true);

  // Connect to the laser(s) if lasers were configured in this robot's parameter
  // file or on the command line, and run laser processing thread if applicable
  // for that laser class.  (For the purposes of this demo, add all
  // possible lasers to ArRobot's list rather than just the ones that were
  // specified with the connectLaser option (so when you enter laser mode, you
  // can then interactively choose which laser to use from the list which will
  // show both connected and unconnected lasers.)
  if (!laserConnector.connectLasers(false, false, true))
  {
    printf("Could not connect to lasers... exiting\n");
    Aria::exit(2);
  }

  // Create and connect to the compass if the robot has one.
  ArTCM2 *compass = compassConnector.create(&robot);
  if(compass && !compass->blockingConnect()) {
    compass = NULL;
  }
  
  // Sleep for a second so some messages from the initial responses
  // from robots and cameras and such can catch up
  ArUtil::sleep(1000);

  // We need to lock the robot since we'll be setting up these modes
  // while the robot task loop thread is already running, and they 
  // need to access some shared data in ArRobot.
  robot.lock();

  // now add all the modes for this demo
  // these classes are defined in ArModes.cpp in ARIA's source code.
  ArModeLaser laser(&robot, "laser", 'l', 'L');
  ArModeTeleop teleop(&robot, "teleop", 't', 'T');
  ArModeUnguardedTeleop unguardedTeleop(&robot, "unguarded teleop", 'u', 'U');
  ArModeWander wander(&robot, "wander", 'w', 'W');
  ArModeGripper gripper(&robot, "gripper", 'g', 'G');
  ArModeCamera camera(&robot, "camera", 'c', 'C');
  ArModeSonar sonar(&robot, "sonar", 's', 'S');
  ArModeBumps bumps(&robot, "bumps", 'b', 'B');
  ArModePosition position(&robot, "position", 'p', 'P', &gyro);
  ArModeIO io(&robot, "io", 'i', 'I');
  ArModeActs actsMode(&robot, "acts", 'a', 'A');
  ArModeCommand command(&robot, "command", 'd', 'D');
  ArModeTCM2 tcm2(&robot, "tcm2", 'm', 'M', compass);


  // activate the default mode
  teleop.activate();

  // turn on the motors
  robot.comInt(ArCommands::ENABLE, 1);

  robot.unlock();
  
  // Block execution of the main thread here and wait for the robot's task loop
  // thread to exit (e.g. by robot disconnecting, escape key pressed, or OS
  // signal)
  robot.waitForRunExit();

  Aria::exit(0);


}
Exemplo n.º 13
0
void ProjectileManager::createLaser(Ogre::Vector3 startPosition, Ogre::Vector3 speed)
{
	int damage(100);
	std::shared_ptr<Laser> laser(new Laser(mSceneMgr, startPosition, damage, speed, mProjectilesList.size()));
	addProjectile(laser);
}
Exemplo n.º 14
0
int main(void){
	// 12 PB0 LASER_R  ---- NICHT MEHR ----
	// 11 PD7 LASER								(Laser)
	// 10 PD6 HAPTIK		OC0A	Timer0	 8 Bit	(Haptik)
	//  9 PD5 LED_FRONT_B	OC0B	Timer0	 8 Bit
	// 13 PB1 IR_CLOCK_-	OC1A	Timer1	16 Bit
	// 14 PB2 LED_FRONT_G	OC1B	Timer1	16 Bit
	// 15 PB3 LED_FRONT_R	OC2A	Timer2	 8 Bit
	//  1 PD3 LED_FRONT_W	OC2B	Timer2	 8 Bit
	// 24 PC1 LDR			ADC1
	// 25 PC2 V_BATT		ADC2
	//  2 PD4 BUTTON_3
	//  7 PB6 BUTTON_2
	//  8 PB7 BUTTON_1
	// 12 PB0 ONOFF

	cli();

	//set pins
	DDRB |= (1 << DDB1) | (1 << DDB2) | (1 << DDB3); //OUTPUT
	DDRD |= (1 << DDD3) | (1 << DDD5) | (1 << DDD6) | (1 << DDD7); //OUTPUT
	DDRB &= ~(1 << PB6) & ~(1 << PB7); //INPUT
	PORTB |= (1 << PB6) | (1 << PB7); //input pullup
	DDRD &= ~(1 << PD4); //INPUT
	PORTD |= (1 << PD4); //input pullup
	
	//ausschalten
	//DDRB |= (1 << DDB0); //OUTPUT
	//PORTB &= ~(1 << DDB0); //LOW

	//init Timers for PWM:
	//https://sites.google.com/site/qeewiki/books/avr-guide/pwm-on-the-atmega328
	//WGM* s157: fast pwm without ctc
	//CS*  s158: _BV(CS20) = prescaler 1 (gilt für a und b)
	//PWM_fequency = clock_speed / [Prescaller_value * (1 + TOP_Value) ] = 8000000/(1*(1+210)) = 37.915 kHz
	
	//Timer 0: Mode 3: Fast PWM, TOP: 0xFF, Update of OCRx: Bottom, TOV1 Flag set on: TOP, Prescaler: 1, Set OC0x on Compare Match
	TCCR0A = _BV(COM0B0) | _BV(COM0A0) | _BV(COM0B1) | _BV(COM0A1) | _BV(WGM00) | _BV(WGM01);
	TCCR0B = _BV(CS00);
	//TIMSK0 |= (1<<TOIE0); //Overflow Interrupt for count millis
	
	//Timer 2: Mode 3: Fast PWM, TOP: 0xFF, Update of OCRx: Bottom, TOV1 Flag set on: TOP, Prescaler: 1, Set OC2x on Compare Match
	TCCR2A = _BV(COM2B0) | _BV(COM2A0) | _BV(COM2B1) | _BV(COM2A1) | _BV(WGM20) | _BV(WGM21);
	TCCR2B = _BV(CS20);
	
	//Timer 1: Mode 14: Fast PWM, inverting mode, Top: ICR1, Update of OCR1x: Bottom, TOV1 Flag set on: TOP, Prescaler: 1
	//https://docs.google.com/spreadsheets/d/1HadMDsU0MGo1LXUr1gKNFrfe4wX_Bq9kbVIwOvD3chk
	TCCR1A = _BV(COM1B0) | _BV(COM1A0) | _BV(COM1B1) | _BV(COM1A1) | _BV(WGM11);
	TCCR1B = _BV(CS10) | _BV(WGM12) | _BV(WGM13);

	//IR carrier frequency to 37.915 kHz:
	ICR1 = 210;
	//IR carrier frequency duty cycle to 50%:
	IR_CLOCK_DUTY_CYCLE = ICR1-ICR1/2;
	
	//switch off all light
	LED_FRONT_R=255;
	LED_FRONT_G=ICR1;
	LED_FRONT_B=255;
	LED_FRONT_W=255;
	HAPTIK=255; //haptik
	//PORTB |= (1 << PB0); //an
	
	//i2c init
	init_twi_slave(I2C_BUS_ADRESS<<1);

	//UART init
	UBRR0H = UBRR_VAL >> 8;
	UBRR0L = UBRR_VAL & 0xFF;
	UCSR0B |= _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); //UART RX, TX und RX-Interrupt einschalten
	UCSR0C = (1<<UCSZ01) | (1<<UCSZ00); //Asynchron 8N1 
	
	sei(); // enable Interrupts global
	
	uint32_t laser_duration_counter=0;
	uint32_t vibrate_duration_counter=0;
	uint32_t muzzle_flash_duration_counter=0;
	uint32_t muzzle_flash_duration_counter_max=0; //fürs ausfaden
	uint16_t ir_delay=0;
	uint8_t ir_count=255;
	
			// return links*256 + rechts
	uint16_t battt = 12345;
	misc_buffer.v_bat_l = battt>>8;
	misc_buffer.v_bat_r = battt;
	
 	while(1){
/*  		// ---------------- blinken + buttons (gedrueckt halten) + ir shoot ----------------
		LED_FRONT_R = 255-1-taster(&PINB, BUTTON_1)*100;
		LED_FRONT_G = ICR1-map8(2, 0, 255, 0, ICR1); //0 bis ICR1
		LED_FRONT_B = 255-1-taster(&PINB, BUTTON_2)*100;
		LED_FRONT_W = 255-1-taster(&PIND, BUTTON_3)*100;
		laser(1); //laser
		HAPTIK = 255-50; //haptik

		_delay_ms(255);
		_delay_ms(255);
		_delay_ms(255);
		
		LED_FRONT_R = 255-0;
		LED_FRONT_G = ICR1-map8(0, 0, 255, 0, ICR1); //0 bis ICR1
		LED_FRONT_B = 255-0;
		LED_FRONT_W = 255-0;
		laser(0); //laser
		HAPTIK = 255-0; //haptik
		
		_delay_ms(255);
		_delay_ms(255);
		_delay_ms(255);
		
		shoot_buffer.playerid = 42;
		shoot_buffer.damage = 123;
		shoot_buffer.enable = 1;
		uint8_t array[] = {shoot_buffer.playerid, shoot_buffer.damage};
		USART_Transmit(shoot_buffer.playerid); //IR_TX: PlayerID
		USART_Transmit(shoot_buffer.damage); //IR_TX: Schaden
		USART_Transmit(crc8(array, 2)); //IR_TX: crc8 checksum
 */
		
 		// ---------------- pew ----------------
		uint8_t brightness = 80;
		if(taster(&PINB, BUTTON_1)){
			if(taster(&PINB, BUTTON_2) && !taster(&PIND, BUTTON_3)){
				LED_FRONT_R = 255-brightness;
				LED_FRONT_G = ICR1-map8(0, 0, 255, 0, ICR1);
				LED_FRONT_B = 255-0;
				LED_FRONT_W = 255-0;
				_delay_ms(20);
				laser(1);
			}else if(!taster(&PINB, BUTTON_2) && taster(&PIND, BUTTON_3)){
				LED_FRONT_R = 255-0;
				LED_FRONT_G = ICR1-map8(brightness, 0, 255, 0, ICR1);
				LED_FRONT_B = 255-0;
				LED_FRONT_W = 255-0;
				_delay_ms(20);
				laser(1);
			}else if(taster(&PINB, BUTTON_2) && taster(&PIND, BUTTON_3)){
				LED_FRONT_R = 255-brightness;
				LED_FRONT_G = ICR1-map8(brightness, 0, 255, 0, ICR1);
				LED_FRONT_B = 255-brightness;
				LED_FRONT_W = 255-brightness;
				_delay_ms(20);
				laser(1);
			}else{
				LED_FRONT_R = 255-0;
				LED_FRONT_G = ICR1-map8(0, 0, 255, 0, ICR1);
				LED_FRONT_B = 255-brightness;
				LED_FRONT_W = 255-0;
				_delay_ms(20);
				laser(1);
			}
			
			
			_delay_ms(30);
			LED_FRONT_R = 255-0;
			LED_FRONT_G = ICR1-map8(0, 0, 255, 0, ICR1);
			LED_FRONT_B = 255-0;
			LED_FRONT_W = 255-0;
			
			_delay_ms(200);
			laser(0);
			_delay_ms(255);
		}
					
		
		
/* 		// ---- buttons ----
		laser_buffer.laser = taster(&PINB, BUTTON_1);
		led_front_buffer.r = taster(&PINB, BUTTON_2)*255;
		led_front_buffer.b = taster(&PIND, BUTTON_3)*255;
 */
	}
}