Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Oussema Harbi <[email protected]>
- * Below are the terms of usage of this file
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- #include <unistd.h>
- #include <iostream>
- #include "smartdrive.h"
- #include <signal.h>
- upm::SmartDrive *drive = NULL;
- void
- sig_handler(int signo)
- {
- printf("got signal\n");
- if (signo == SIGINT) {
- printf("exiting application\n");
- //if (drive != NULL)
- //delete drive;
- exit (0);
- }
- }
- int
- main(int argc, char **argv)
- {
- float voltage = 0;
- std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
- sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
- // Instantiate a a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
- drive = new upm::SmartDrive(1);
- drive->command(0x52);
- drive->StopMotor(Motor_ID_BOTH, Action_Brake);
- sleep(5);
- std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
- std::cout << "Pos M1 : " << drive->ReadTachometerPosition(Motor_ID_1)<< std::endl;
- std::cout << "Pos M2 : " << drive->ReadTachometerPosition(Motor_ID_2)<< std::endl;
- //Set motor M1 to run for 300seconds, with speed of 15RPM, waith for it to finish and then Brake It
- drive->Run_Seconds(Motor_ID_BOTH, Dir_Reverse, 90, 70, true, Action_Brake );
- std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
- std::cout << "Pos M1 : " << drive->ReadTachometerPosition(Motor_ID_1) << std::endl;
- //you pass ID of motor to run to functions
- //If you want to run only motor 1, you use Motor_ID_1
- //IF you want to run only motor 2, you use Motor_ID_2
- //If you want to run 2 motors, you use Motor_ID_BOTH
- // ok ?
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment