Skip to content
Snippets Groups Projects
Commit 5ca25869 authored by fortissBot's avatar fortissBot
Browse files

Code Generation for Sensors and Rumblepad

parent 135ff00f
No related branches found
No related tags found
No related merge requests found
Showing
with 2470 additions and 42 deletions
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Thomas Boehm, Florian Hoelzl - initial API and implementation
*******************************************************************************/
#ifndef INC_RUMBLEPAD_H_
#define INC_RUMBLEPAD_H_
#include <stdint.h>
#define RUMBLEPAD_AXIS_LEFT_STICK_HORIZONTAL 0
#define RUMBLEPAD_AXIS_LEFT_STICK_VERTICAL 1
#define RUMBLEPAD_AXIS_L2 2
#define RUMBLEPAD_AXIS_RIGHT_STICK_HORIZONTAL 3
#define RUMBLEPAD_AXIS_RIGHT_STICK_VERTICAL 4
#define RUMBLEPAD_AXIS_R2 5
//#define RUMBLEPAD_AXIS_CROSS_PAD_HORIZONTAL 4
//#define RUMBLEPAD_AXIS_CROSS_PAD_VERTICAL 5
#define RUMBLEPAD_BUTTON_A 6
#define RUMBLEPAD_BUTTON_B 7
#define RUMBLEPAD_BUTTON_Y 8
#define RUMBLEPAD_BUTTON_X 9
#define RUMBLEPAD_BUTTON_L1 10
#define RUMBLEPAD_BUTTON_R1 11
#define RUMBLEPAD_BUTTON_SELECT 12
#define RUMBLEPAD_BUTTON_START 13
#define RUMBLEPAD_BUTTON_L3 14
#define RUMBLEPAD_BUTTON_R3 15
#define RUMBLEPAD_BUTTON_HOME 16
#define RUMBLEPAD_DPAD_UP 17
#define RUMBLEPAD_DPAD_DOWN 18
#define RUMBLEPAD_DPAD_LEFT 19
#define RUMBLEPAD_DPAD_RIGHT 20
//#define RUMBLEPAD_BUTTON_LEFT_STICK 16
//#define RUMBLEPAD_BUTTON_RIGHT_STICK 17
#define RUMBLEPAD_BUTTON_STATE_PRESSED 1
#define RUMBLEPAD_BUTTON_STATE_NPRESSED 0
struct rumblepad_configuration {
const char* device_id;
uint64_t waiting_sleep_in_micros;
void (*axis_callback)(uint8_t axis, int16_t value);
void (*button_callback)(uint8_t button, uint16_t old_value, uint16_t new_value);
};
typedef struct rumblepad_configuration rumblepad_configuration_t;
/** Initializes the rumblepad and starts its thread. */
void rumblepad_initialize(rumblepad_configuration_t* configuration);
/** Get the axis position for the given axis. */
int16_t rumblepad_get_axis_position(uint8_t axisID);
/** Get the button state for the given button. */
int16_t rumblepad_get_button_state(uint8_t buttonID);
/** Terminates the rumblepad thread and frees its resources. */
void rumblepad_terminate();
#endif /* INC_RUMBLEPAD_H_ */
......@@ -3,12 +3,14 @@
#include <stdint.h>
void temp_actuator_initialize(const char * device);
int temp_actuator_initialize(const char * device);
int temp_actuator_get_position(uint8_t channel);
int temp_actuator_set_target(uint8_t channel, uint16_t target);
int temp_actuator_device_set_target(int device, uint8_t channel, uint16_t target);
void temp_actuator_terminate();
#endif /* INC_TEMP_ACTUATOR_H_ */
No preview for this file type
......@@ -2,21 +2,21 @@
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="model" nsURI="http://www.fortiss.org/af3/platform/raspberry"
nsPrefix="org-fortiss-af3-platform-raspberry">
<eClassifiers xsi:type="ecore:EClass" name="RaspberryPi" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//ExecutionUnit">
<eClassifiers xsi:type="ecore:EClass" name="RaspberryPi" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//ExecutionUnit">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="canCoordinationID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="ipAddress" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="coordinatorUnit" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="cycleTime" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CanBus" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//TransmissionUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="CanConnector" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Transceiver"/>
<eClassifiers xsi:type="ecore:EClass" name="ActuatorPWM" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Transmitter">
<eClassifiers xsi:type="ecore:EClass" name="CanBus" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//TransmissionUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="CanConnector" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Transceiver"/>
<eClassifiers xsi:type="ecore:EClass" name="ActuatorPWM" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Transmitter">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="channelID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
</eClassifiers>
<eSubpackages name="gamepad" nsURI="http://www.fortiss.org/af3/platform/raspberry/gamepad"
nsPrefix="org-fortiss-af3-platform-raspberry-gamepad">
<eClassifiers xsi:type="ecore:EClass" name="GamepadReceiverBase" abstract="true"
eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver"/>
eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver"/>
<eClassifiers xsi:type="ecore:EClass" name="Button1" eSuperTypes="#//gamepad/GamepadReceiverBase"/>
<eClassifiers xsi:type="ecore:EClass" name="Button2" eSuperTypes="#//gamepad/GamepadReceiverBase"/>
<eClassifiers xsi:type="ecore:EClass" name="Button3" eSuperTypes="#//gamepad/GamepadReceiverBase"/>
......@@ -32,25 +32,25 @@
</eSubpackages>
<eSubpackages name="brick" nsURI="http://www.fortiss.org/af3/platform/raspberry/brick"
nsPrefix="org-fortiss-af3-platform-raspberry">
<eClassifiers xsi:type="ecore:EClass" name="UIDUnit" abstract="true" eSuperTypes="../../org.fortiss.tooling.kernel/model/kernel.ecore#//INamedCommentedElement">
<eClassifiers xsi:type="ecore:EClass" name="UIDUnit" abstract="true" eSuperTypes="platform:/resource/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedCommentedElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="uniqueBrickletID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="UltraSonicSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="LaserRangeSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AccelerationXSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AccelerationYSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AccelerationZSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AngularVelocityXSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AngularVelocityYSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AngularVelocityZSensor" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="ActuatorDigits" eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Transmitter #//brick/UIDUnit">
<eClassifiers xsi:type="ecore:EClass" name="UltraSonicSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="LaserRangeSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AccelerationXSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AccelerationYSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AccelerationZSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AngularVelocityXSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AngularVelocityYSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="AngularVelocityZSensor" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver #//brick/UIDUnit"/>
<eClassifiers xsi:type="ecore:EClass" name="ActuatorDigits" eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Transmitter #//brick/UIDUnit">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="showHexValue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
</eSubpackages>
<eSubpackages name="rumblepad" nsURI="http://www.fortiss.org/af3/platform/raspberry/rumblepad"
nsPrefix="org-fortiss-af3-platform-raspberry-rumblepad">
<eClassifiers xsi:type="ecore:EClass" name="RumblepadReceiverBase" abstract="true"
eSuperTypes="../../org.fortiss.af3.platform/model/platform.ecore#//Receiver"/>
eSuperTypes="platform:/resource/org.fortiss.af3.platform/model/platform.ecore#//Receiver"/>
<eClassifiers xsi:type="ecore:EClass" name="ButtonA" eSuperTypes="#//rumblepad/RumblepadReceiverBase"/>
<eClassifiers xsi:type="ecore:EClass" name="ButtonB" eSuperTypes="#//rumblepad/RumblepadReceiverBase"/>
<eClassifiers xsi:type="ecore:EClass" name="ButtonX" eSuperTypes="#//rumblepad/RumblepadReceiverBase"/>
......
......@@ -18,10 +18,6 @@
<genClasses ecoreClass="raspberry.ecore#//ActuatorPWM">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute raspberry.ecore#//ActuatorPWM/channelID"/>
</genClasses>
<genClasses ecoreClass="raspberry.ecore#//ActuatorDigits">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute raspberry.ecore#//ActuatorDigits/showHexValue"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute raspberry.ecore#//ActuatorDigits/uniqueBrickletID"/>
</genClasses>
<nestedGenPackages prefix="Gamepad" basePackage="org.fortiss.af3.platform.raspberry.model"
disposableProviderFactory="true" ecorePackage="raspberry.ecore#//gamepad">
<genClasses image="false" ecoreClass="raspberry.ecore#//gamepad/GamepadReceiverBase"/>
......@@ -51,6 +47,34 @@
<genClasses ecoreClass="raspberry.ecore#//brick/AngularVelocityXSensor"/>
<genClasses ecoreClass="raspberry.ecore#//brick/AngularVelocityYSensor"/>
<genClasses ecoreClass="raspberry.ecore#//brick/AngularVelocityZSensor"/>
<genClasses ecoreClass="raspberry.ecore#//brick/ActuatorDigits">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute raspberry.ecore#//brick/ActuatorDigits/showHexValue"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="Rumblepad" basePackage="org.fortiss.af3.platform.raspberry.model"
disposableProviderFactory="true" ecorePackage="raspberry.ecore#//rumblepad">
<genClasses image="false" ecoreClass="raspberry.ecore#//rumblepad/RumblepadReceiverBase"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonA"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonB"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonX"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonY"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonL1"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonR1"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonL3"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonR3"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/Left_StickX_Position"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/Left_StickY_Position"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/Right_StickX_Position"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/Right_StickY_Position"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/L2_Position"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/R2_Position"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/DPadUp"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/DPadDown"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/DPadLeft"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/DPadRight"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonStart"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonSelect"/>
<genClasses ecoreClass="raspberry.ecore#//rumblepad/ButtonHome"/>
</nestedGenPackages>
</genPackages>
</genmodel:GenModel>
......@@ -42,6 +42,7 @@ final class HeaderCopyGenerator {
incLibPack.addUnit(copyAF3Hal("canthread.h"));
incLibPack.addUnit(copyAF3Hal("debugprint.h"));
incLibPack.addUnit(copyAF3Hal("gamepad.h"));
incLibPack.addUnit(copyAF3Hal("rumblepad.h"));
incLibPack.addUnit(copyAF3Hal("protocol_can.h"));
incLibPack.addUnit(copyAF3Hal("protocol_control_center.h"));
incLibPack.addUnit(copyAF3Hal("protocol_coordinator.h"));
......@@ -49,6 +50,11 @@ final class HeaderCopyGenerator {
incLibPack.addUnit(copyAF3Hal("protocol_worker.h"));
incLibPack.addUnit(copyAF3Hal("temp_actuator.h"));
incLibPack.addUnit(copyAF3Hal("timeutil.h"));
incLibPack.addUnit(copyBrick("ip_connection.h"));
incLibPack.addUnit(copyBrick("bricklet_distance_us.h"));
incLibPack.addUnit(copyBrick("bricklet_laser_range_finder.h"));
incLibPack.addUnit(copyBrick("brick_imu_v2.h"));
incLibPack.addUnit(copyBrick("bricklet_segment_display_4x7.h"));
}
/** Copies the AF3 HAL header file. */
......
......@@ -93,7 +93,8 @@ public class RaspberryPIExecutable extends ExecutionUnitExecutableBase<Raspberry
addLogicalComponentCode(deployedComponents, context, sourcePackage);
addEclipseCProjectFiles(sourcePackage, modelElement.getName());
addStaticLibraries(sourcePackage);
addConfigureAndMakedefsFiles(sourcePackage, modelElement.getName(), LIB_NAMES);
addConfigureAndMakedefsFiles(sourcePackage, modelElement.getName(),
LIB_NAMES_WITH_BRICK);
addMainFile(sourcePackage, deployedComponents, deployedPorts, context);
} catch(Exception ex) {
error(AF3PlatformRaspberryActivator.getDefault(), ex.getMessage(), ex);
......
......@@ -61,14 +61,16 @@ public final class RasPiCTemplates {
}
/** Returns the 'main.c' file configured using the given arguments. */
public static AbstractUnit getSingleUnitMainCFile(String unitName, int cycletimeInMillis,
String systemIncludes, String systemInitCode, String workerCode) {
public static AbstractUnit
getSingleUnitMainCFile(String unitName, int cycletimeInMillis, String systemIncludes,
String systemInitCode, String workerCode, String sensorVariables) {
StringTemplate template = makeTemplate("SingleUnitMainFile.stg", "MainFile");
template.setAttribute("UNIT_NAME", unitName);
template.setAttribute("CYCLE_TIME_IN_MILLIS", cycletimeInMillis);
template.setAttribute("SYSTEM_INCLUDES", systemIncludes);
template.setAttribute("SYSTEM_INIT_CODE", systemInitCode);
template.setAttribute("WORKER_CODE", workerCode);
template.setAttribute("SENSOR_VARIABLES", sensorVariables);
StaticContentSourceUnit unit =
createStaticContentSourceUnit("main.c", template.toString(), false);
return unit;
......
......@@ -4,7 +4,8 @@ MainFile(UNIT_NAME,
CYCLE_TIME_IN_MILLIS,
SYSTEM_INCLUDES,
SYSTEM_INIT_CODE,
WORKER_CODE) ::= <<
WORKER_CODE,
SENSOR_VARIABLES) ::= <<
// due to current data dictionary declaration of GENTYPE_boolean
// system include must be first
$SYSTEM_INCLUDES$
......@@ -24,7 +25,10 @@ $SYSTEM_INCLUDES$
static uint64_t step = 0;
$SENSOR_VARIABLES$
static void worker() {
uint64_t curr_time = time_util_get_current_micros();
step++;
$WORKER_CODE$
}
......@@ -36,8 +40,10 @@ static uint64_t delta_time_in_micros;
static uint64_t local_logical_clock;
int main(int argc, char** argv) {
local_logical_clock = 1;
// set AF3 unit name used when communicating with CC
af3_set_execution_unit_identifier("$UNIT_NAME$");
uint32_t cycle_time = $CYCLE_TIME_IN_MILLIS$;
// TODO: initialize ControlCenter connection
$SYSTEM_INIT_CODE$
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment