Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed ros_lib_kinetic
initializations.cpp@6:2ffa254e8f6e, 2018-03-06 (annotated)
- Committer:
- MikeGray92
- Date:
- Tue Mar 06 21:44:07 2018 +0000
- Revision:
- 6:2ffa254e8f6e
- Parent:
- 4:89ebfa37663b
- Child:
- 7:950b3c3b5a2b
Added Comments; Changed the order of rosInput values (0 - neg, 1 -nothing, 2 - pos); Changed Roll limits
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 1 | #include <std_msgs/Empty.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 2 | #include <std_msgs/Float32MultiArray.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 3 | #include <initializations.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 4 | #include <ros.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 5 | #include <definitions.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 6 | #include <prototypes.h> |
MikeGray92 | 3:527f0b949839 | 7 | #include "mbed.h" |
MikeGray92 | 2:0537a8007a39 | 8 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 9 | // Initializations |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 10 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 11 | void setupGimbal(){ |
MikeGray92 | 6:2ffa254e8f6e | 12 | // Set the Gimbal at the zero position. |
MikeGray92 | 6:2ffa254e8f6e | 13 | gimbal.servo(YAWID, YAWZERO, 50); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 14 | control.yaw = YAWZERO; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 15 | wait(0.1); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 16 | gimbal.servo(PITCHID, PITCHZERO, 50); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 17 | control.pitch = PITCHZERO; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 18 | wait(0.1); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 19 | gimbal.servo(ROLLID, ROLLZERO, 50); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 20 | control.roll = ROLLZERO; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 21 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 22 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 23 | void setupLift(){ |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 24 | |
MikeGray92 | 4:89ebfa37663b | 25 | startHallInt(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 26 | liftSpeed.period_us(50); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 27 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 28 | // Find the bottom position. Go down at lowest speed and set zero point. |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 29 | liftDirection.write(LIFTDOWN); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 30 | liftSpeed.write(0.3); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 31 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 32 | // Wait until the motor stalls, know the motor is at bottom. |
MikeGray92 | 4:89ebfa37663b | 33 | while(stallcount < 3){wait(.01);} |
MikeGray92 | 4:89ebfa37663b | 34 | liftSpeed.write(0); |
MikeGray92 | 4:89ebfa37663b | 35 | currentPosition = 0; |
MikeGray92 | 4:89ebfa37663b | 36 | stopHallInt(); |
MikeGray92 | 4:89ebfa37663b | 37 | wait(0.1); |
MikeGray92 | 6:2ffa254e8f6e | 38 | // Lift up from stalling position |
MikeGray92 | 4:89ebfa37663b | 39 | liftDirection.write(LIFTUP); |
MikeGray92 | 4:89ebfa37663b | 40 | liftSpeed.write(0.3); |
MikeGray92 | 4:89ebfa37663b | 41 | wait(0.1); |
MikeGray92 | 6:2ffa254e8f6e | 42 | //Stop |
MikeGray92 | 4:89ebfa37663b | 43 | liftSpeed.write(0); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 44 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 45 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 46 | void setupROSNode(ros::NodeHandle& nh, ros::Subscriber<std_msgs::Float32MultiArray>& sub){ |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 47 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 48 | nh.getHardware()->setBaud(57600); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 49 | nh.initNode(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 50 | nh.subscribe(sub); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 51 | } |
MikeGray92 | 4:89ebfa37663b | 52 | |
MikeGray92 | 6:2ffa254e8f6e | 53 | void startHallInt() { // Starting hall effect timer interrupt |
MikeGray92 | 4:89ebfa37663b | 54 | hallInt.attach(&hallInterrupt, 0.03); |
MikeGray92 | 4:89ebfa37663b | 55 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 56 | |
MikeGray92 | 6:2ffa254e8f6e | 57 | void stopHallInt() { // Stopping hall effect timer interrupt |
MikeGray92 | 4:89ebfa37663b | 58 | hallInt.detach(); |
MikeGray92 | 4:89ebfa37663b | 59 | } |
MikeGray92 | 4:89ebfa37663b | 60 |