From ca55de79b715f8656fe740167bb474fc4608eef8 Mon Sep 17 00:00:00 2001 From: alextel69 Date: Sat, 1 Nov 2014 16:37:19 +0200 Subject: [PATCH 1/3] Add DO_SET_SERVO to core library --- .../droidplanner/core/mission/Mission.java | 4 ++ .../core/mission/MissionItemType.java | 5 +- .../core/mission/commands/SetServo.java | 72 +++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Core/src/org/droidplanner/core/mission/commands/SetServo.java diff --git a/Core/src/org/droidplanner/core/mission/Mission.java b/Core/src/org/droidplanner/core/mission/Mission.java index d57ae10734..63591a7438 100644 --- a/Core/src/org/droidplanner/core/mission/Mission.java +++ b/Core/src/org/droidplanner/core/mission/Mission.java @@ -16,6 +16,7 @@ import org.droidplanner.core.mission.commands.ChangeSpeed; import org.droidplanner.core.mission.commands.EpmGripper; import org.droidplanner.core.mission.commands.ReturnToHome; +import org.droidplanner.core.mission.commands.SetServo; import org.droidplanner.core.mission.commands.Takeoff; import org.droidplanner.core.mission.waypoints.Circle; import org.droidplanner.core.mission.waypoints.Land; @@ -257,6 +258,9 @@ private List processMavLinkMessages(List msgs) { for (msg_mission_item msg : msgs) { switch (msg.command) { + case MAV_CMD.MAV_CMD_DO_SET_SERVO: + received.add(new SetServo(msg, this)); + break; case MAV_CMD.MAV_CMD_NAV_WAYPOINT: received.add(new Waypoint(msg, this)); break; diff --git a/Core/src/org/droidplanner/core/mission/MissionItemType.java b/Core/src/org/droidplanner/core/mission/MissionItemType.java index 351d5cea27..4fa9183bf2 100644 --- a/Core/src/org/droidplanner/core/mission/MissionItemType.java +++ b/Core/src/org/droidplanner/core/mission/MissionItemType.java @@ -7,6 +7,7 @@ import org.droidplanner.core.mission.commands.ChangeSpeed; import org.droidplanner.core.mission.commands.EpmGripper; import org.droidplanner.core.mission.commands.ReturnToHome; +import org.droidplanner.core.mission.commands.SetServo; import org.droidplanner.core.mission.commands.Takeoff; import org.droidplanner.core.mission.survey.Survey; import org.droidplanner.core.mission.waypoints.Circle; @@ -19,7 +20,7 @@ public enum MissionItemType { WAYPOINT("Waypoint"), SPLINE_WAYPOINT("Spline Waypoint"), TAKEOFF("Takeoff"), RTL( "Return to Launch"), LAND("Land"), CIRCLE("Circle"), ROI("Region of Interest"), SURVEY( - "Survey"), CYLINDRICAL_SURVEY("Structure Scan"), CHANGE_SPEED("Change Speed"), CAMERA_TRIGGER("Camera Trigger"), EPM_GRIPPER("EPM"); + "Survey"), CYLINDRICAL_SURVEY("Structure Scan"), CHANGE_SPEED("Change Speed"), CAMERA_TRIGGER("Camera Trigger"), EPM_GRIPPER("EPM"), SET_SERVO("Set Servo"); private final String name; @@ -57,6 +58,8 @@ public MissionItem getNewItem(MissionItem referenceItem) throws IllegalArgumentE return new Survey(referenceItem.getMission(), Collections. emptyList()); case CYLINDRICAL_SURVEY: return new StructureScanner(referenceItem); + case SET_SERVO: + return new SetServo(referenceItem); default: throw new IllegalArgumentException("Unrecognized mission item type (" + name + ")" + "."); diff --git a/Core/src/org/droidplanner/core/mission/commands/SetServo.java b/Core/src/org/droidplanner/core/mission/commands/SetServo.java new file mode 100644 index 0000000000..997b1ffb82 --- /dev/null +++ b/Core/src/org/droidplanner/core/mission/commands/SetServo.java @@ -0,0 +1,72 @@ +package org.droidplanner.core.mission.commands; + +import java.util.List; + +import org.droidplanner.core.helpers.units.Altitude; +import org.droidplanner.core.mission.Mission; +import org.droidplanner.core.mission.MissionItem; +import org.droidplanner.core.mission.MissionItemType; + +import com.MAVLink.Messages.ardupilotmega.msg_mission_item; +import com.MAVLink.Messages.enums.MAV_CMD; + +public class SetServo extends MissionCMD { + + private int pwm; + private int channel; + + public SetServo(MissionItem item) { + super(item); + } + + public SetServo(msg_mission_item msg, Mission mission) { + super(mission); + unpackMAVMessage(msg); + } + + public SetServo(Mission mission, int channel, int pwm) { + super(mission); + this.channel = channel; + this.pwm = pwm; + } + + + @Override + public void unpackMAVMessage(msg_mission_item mavMsg) { + channel = (int) mavMsg.param1; + pwm = (int) mavMsg.param2; + + } + + @Override + public MissionItemType getType() { + return MissionItemType.SET_SERVO; + } + + @Override + public List packMissionItem() { + List list = super.packMissionItem(); + msg_mission_item mavMsg = list.get(0); + mavMsg.command = MAV_CMD.MAV_CMD_DO_SET_SERVO; + mavMsg.param1 = channel; + mavMsg.param2 = pwm; + return list; + } + + public float getPwm() { + return pwm; + } + + public float getChannel() { + return channel; + } + + public void setPwm(int pwm) { + this.pwm = pwm; + } + + public void setChannel(int channel) { + this.channel = channel; + } + +} From 2e77f154118c31e931cf4c7596c0ca7abb79e951 Mon Sep 17 00:00:00 2001 From: alextel69 Date: Sat, 1 Nov 2014 21:30:36 +0200 Subject: [PATCH 2/3] Fix getter return value --- Core/src/org/droidplanner/core/mission/commands/SetServo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/droidplanner/core/mission/commands/SetServo.java b/Core/src/org/droidplanner/core/mission/commands/SetServo.java index 997b1ffb82..c52f996992 100644 --- a/Core/src/org/droidplanner/core/mission/commands/SetServo.java +++ b/Core/src/org/droidplanner/core/mission/commands/SetServo.java @@ -53,11 +53,11 @@ public List packMissionItem() { return list; } - public float getPwm() { + public int getPwm() { return pwm; } - public float getChannel() { + public int getChannel() { return channel; } From 05e769160303bbc2b90462b27333289fdaa74264 Mon Sep 17 00:00:00 2001 From: alextel69 Date: Sat, 1 Nov 2014 21:31:20 +0200 Subject: [PATCH 3/3] Implement DO_SET_SERVO on Android side --- .../fragment_editor_detail_set_servo.xml | 117 ++++++++++++++++++ Android/res/values/strings.xml | 6 + .../item/fragments/MissionDetailFragment.java | 3 + .../item/fragments/SetServoFragment.java | 83 +++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 Android/res/layout/fragment_editor_detail_set_servo.xml create mode 100644 Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java diff --git a/Android/res/layout/fragment_editor_detail_set_servo.xml b/Android/res/layout/fragment_editor_detail_set_servo.xml new file mode 100644 index 0000000000..b88b44af06 --- /dev/null +++ b/Android/res/layout/fragment_editor_detail_set_servo.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Android/res/values/strings.xml b/Android/res/values/strings.xml index c4715f73e8..001369b2a7 100644 --- a/Android/res/values/strings.xml +++ b/Android/res/values/strings.xml @@ -182,6 +182,7 @@ Land Change Speed Camera Trigger + Set Servo EPM Circle Loiter @@ -204,9 +205,13 @@ Changes the home location either to the current location or a specified location. Change vehicle speed until the end of this mission. Trigger the camera shutter at regular distance intervals. + Move a servo to a particular PWM value. Release the payload of the EPM grabber Sets a location and altitude to point copter towards and to aim an optional camera. Repeat waypoint + + + PWM: One cannot add new waypoints after LAND or RTL @@ -346,6 +351,7 @@ m/s Speed Length + Channel Ground Speed Air Speed --° diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionDetailFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionDetailFragment.java index 0cb7749c5b..64c11d1ff3 100644 --- a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionDetailFragment.java +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/MissionDetailFragment.java @@ -107,6 +107,9 @@ public static MissionDetailFragment newInstance(MissionItemType itemType) { case EPM_GRIPPER: fragment = new MissionEpmGrabberFragment(); break; + case SET_SERVO: + fragment = new SetServoFragment(); + break; default: fragment = null; break; diff --git a/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java new file mode 100644 index 0000000000..c00d092718 --- /dev/null +++ b/Android/src/org/droidplanner/android/proxy/mission/item/fragments/SetServoFragment.java @@ -0,0 +1,83 @@ +package org.droidplanner.android.proxy.mission.item.fragments; + +import org.droidplanner.R; +import org.droidplanner.android.widgets.spinnerWheel.CardWheelHorizontalView; +import org.droidplanner.android.widgets.spinnerWheel.adapters.NumericWheelAdapter; +import org.droidplanner.core.mission.MissionItem; +import org.droidplanner.core.mission.MissionItemType; +import org.droidplanner.core.mission.commands.SetServo; + +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.EditText; + +public class SetServoFragment extends MissionDetailFragment implements + CardWheelHorizontalView.OnCardWheelChangedListener, TextWatcher { + + @Override + protected int getResource() { + return R.layout.fragment_editor_detail_set_servo; + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + typeSpinner.setSelection(commandAdapter + .getPosition(MissionItemType.SET_SERVO)); + + SetServo item = (SetServo) getMissionItems().get(0); + + final NumericWheelAdapter adapter = new NumericWheelAdapter( + getActivity().getApplicationContext(), + R.layout.wheel_text_centered, 1, 8, "%d"); + final CardWheelHorizontalView cardChannelPicker = (CardWheelHorizontalView) view + .findViewById(R.id.picker1); + final EditText pwmEditText = (EditText) view + .findViewById(R.id.PwmEditText); + + cardChannelPicker.setViewAdapter(adapter); + cardChannelPicker.addChangingListener(this); + cardChannelPicker.setCurrentValue((int) item.getChannel()); + + pwmEditText.setText(Integer.toString(item.getPwm())); + pwmEditText.addTextChangedListener(this); + + } + + @Override + public void onChanged(CardWheelHorizontalView wheel, int oldValue, + int newValue) { + switch (wheel.getId()) { + case R.id.picker1: + for (MissionItem missionItem : getMissionItems()) { + SetServo item = (SetServo) missionItem; + item.setChannel(newValue); + } + break; + } + } + + @Override + public void afterTextChanged(Editable editable) { + + } + + @Override + public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, + int arg3) { + + } + + @Override + public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) { + if (!s.toString().isEmpty()) { + for (MissionItem missionItem : getMissionItems()) { + SetServo item = (SetServo) missionItem; + item.setPwm(Integer.valueOf(s.toString())); + } + } + + } +}