I moved from an STM32F031K6 to an STM32L412 for more speed. I found that the PWM no longer works in my code, but im unsure why. I am using cubeIDE and have the relevant outputs selected as PWM outputs. The setup preamble from the cubeIDE is as follows -
static void MX_TIM1_Init(void)
{
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.BreakFilter = 0;
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
sBreakDeadTimeConfig.Break2Filter = 0;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_MspPostInit(&htim1);
}
Before I just set up the timers with the inbuilt cube software - all i needed to do was put a number in the output compare register. Now it doesn't work, I don't know what I'm missing - I noticed that the timers aren't enabled by the HAL setup but when I enable them in TIM1_CR1 it still doesn't work. Can anyone help?
A Timer that counts from 0 to 0 doesn't count much.
Maybe you should change the upper counter limit:
sConfigOC.Pulse = 0;
Related
#define CA "/mnt/key/ca.crt"
#define CLIENT_KEY "/mnt/key/client.key"
#define CLIENT_CRT "/mnt/key/client.crt"
void onConnectFailure(void *context, MQTTAsync_failureData *response)
{
finished = 1;
printf("[CS55]Connect failed, rc %d\n", response ? response->code : 0);
delay(1000);
connect_server();
}
void connect_server()
{
if (MQTTAsync_connect(client, &conn_opts) != MQTTASYNC_SUCCESS)
{
printf("[CS55]connect_server()\n");
finished = 1;
}
}
void mqtt_connect()//连接
{
MQTTAsync_SSLOptions ssl_opts = MQTTAsync_SSLOptions_initializer;
pthread_mutex_init(&serial_mute, NULL); //互斥锁
MQTTAsync_create(&client, mqtt_addr, client_id, MQTTCLIENT_PERSISTENCE_NONE, NULL);
MQTTAsync_setCallbacks( //设置回调
client,
NULL,
connlost,
msgarrvd,
NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.onSuccess = onConnect;
conn_opts.onFailure = onConnectFailure;
conn_opts.username = username;
conn_opts.password = password;
conn_opts.context = client;
ssl_opts.struct_version = 5;
ssl_opts.sslVersion = MQTT_SSL_VERSION_TLS_1_2;
ssl_opts.verify = true;
ssl_opts.keyStore = CLIENT_KEY;
ssl_opts.trustStore = CLIENT_CRT;
ssl_opts.enableServerCertAuth = true;
ssl_opts.CApath = CA;
conn_opts.ssl = &ssl_opts;
// ssl_opts.enabledCipherSuites = "TLSv1";
int rc;
if ((rc = MQTTAsync_connect(client, &conn_opts))!= MQTTASYNC_SUCCESS)
{
printf("[CS55]MQTTAsync_connect return %d\n",rc);
finished = 1;
}
// connect_server(); //开始请求连接服务器
while (subscribe_fail != 1) //while(订阅成功)
{
delay(1000); //延迟1000ms
}
MQTTAsync_disconnectOptions disc_opts = MQTTAsync_disconnectOptions_initializer;
disc_opts.onSuccess = onDisconnect;
rc = MQTTAsync_disconnect(client, &disc_opts);
if (rc != MQTTASYNC_SUCCESS)
{
//printf("Failed to start disconnect, return code %d\n", rc);
}
MQTTAsync_destroy(&client);
}
log:
[CS55]Connect failed, rc -1
[CS55]Connect failed, rc -1
[CS55]Connect failed, rc -1
[CS55]Connect failed, rc -1
After I start the program, I will execute the callback function onConnectFailure, and then print the log of connection failure all the time. After debugging for a long time, I don't know where the problem is. I may need help。
I tried to add certificate authentication in mqtt, but I couldn't connect to the server. I didn't find a reference use case. If so, please share it with me
connopts.ssl = &ssl_opts;
connopts.ssl->trustStore = CA;
connopts.ssl->privateKey = CLIENT_KEY;
connopts.ssl->keyStore = CLIENT_CRT;
connopts.ssl->enableServerCertAuth = ture;
connopts.ssl->verify = true;
Refer to the above code, pay attention to using SSL protocol when connecting to the server ssl://11.22.33.44 :8883。
I'm getting VK_ERROR_FEATURE_NOT_PRESENT(-8).
But i'm using vkGetPhysicalDeviceFeatures to get features.
My Code:
std::vector<VkDeviceQueueCreateInfo> LogicalDevice::CreateDeviceQueueCreateInfos(QueueFamilies queueFamilies)
{
std::vector uniqueQueueFamilies = queueFamilies.GetUniqueQueueFamilies();
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
for (auto queueFamily : uniqueQueueFamilies)
{
const int countOfQueues = queueFamily.CountOfQueues;
std::vector<float> queuePriorities(countOfQueues);
for (int indexOfPriority = 0; indexOfPriority < countOfQueues; indexOfPriority++)
{
queuePriorities[indexOfPriority] = 1.0f - ( (float) indexOfPriority / countOfQueues);
}
VkDeviceQueueCreateInfo queueCreateInfo{};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.queueFamilyIndex = queueFamily.Index.value();
queueCreateInfo.queueCount = queueFamily.CountOfQueues;
queueCreateInfo.flags = queueFamily.Flags;
queueCreateInfo.pQueuePriorities = queuePriorities.data();
queueCreateInfos.push_back(queueCreateInfo);
}
return queueCreateInfos;
}
VkDeviceCreateInfo LogicalDevice::GetDeviceCreateInfo(std::vector<VkDeviceQueueCreateInfo> deviceQueueCreateInfos, VkPhysicalDevice physicalDevice)
{
VkPhysicalDeviceFeatures deviceFeatures{};
vkGetPhysicalDeviceFeatures(physicalDevice, &deviceFeatures);
VkDeviceCreateInfo deviceCreateInfo{};
deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
deviceCreateInfo.queueCreateInfoCount = static_cast<uint32_t>(deviceQueueCreateInfos.size());
deviceCreateInfo.pQueueCreateInfos = deviceQueueCreateInfos.data();
deviceCreateInfo.pEnabledFeatures = &deviceFeatures;
return deviceCreateInfo;
}
void LogicalDevice::Initialize(VkPhysicalDevice physicalDevice, VkSurfaceKHR surfaceForPickingPhysicalDevice)
{
m_queueFamilies = QueueFamilies::GetQueueFamilies(physicalDevice, surfaceForPickingPhysicalDevice);
std::vector<VkDeviceQueueCreateInfo> deviceQueueCreateInfos = CreateDeviceQueueCreateInfos(m_queueFamilies);
VkDeviceCreateInfo deviceCreateInfo = GetDeviceCreateInfo(deviceQueueCreateInfos, physicalDevice);
VkResult result = vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &m_vulkanDevice);
if (result != VK_SUCCESS)
{
throw new std::runtime_error("Cannot create logical device.");
}
}
The deviceFeature variable that you read the features into and which is pointed at in the create info structure is local to GetDeviceCreateInfo. This is out-of-scope at the point where you call vkCreateDevice, which results in undefined behavior. You're probably getting random junk at device creation time instead, which causes that error.
I am trying to translate an old flash animation with animate. On the original flash animation the map image is draggable and zoomable but the map ´s borders always stick to the sides of the stage if you pan it or zoom it all the way.
On my test i grabbed some code that allows panning and zooming but the map crosses the stage boundaries if you pan all the way, in fact you can make the map dissapear of the stage.
I think there should be a way to draw like a secondary outer stage and not let the map image go beyond it.
This is the code I have.
var that = this;
var clickedX;
var clickedY;
var isDragging = false;
var friction = 0.85;
var speedX = 0;
var speedY = 0;
var mapOriginalX = this.map.x;
var mapOriginalY = this.map.y;
var mapNudge = 5;
var minScale = 0.25;
var maxScale = 3;
function onMouseWheel(e)
{
var delta;
if (e == window.event)
delta = -10 / window.event.wheelDeltaY;
else
delta = e.detail / 30;
var zoomFactor = delta;
scaleMap(zoomFactor);
}
function mouseDown(e)
{
clickedX = stage.mouseX;
clickedY = stage.mouseY;
isDragging = true;
console.log(stage.mouseX);
console.log(stage.mouseY);
}
function stageMouseUp(e)
{
isDragging = false;
}
function update(e)
{
if (isDragging)
{
speedX = stage.mouseX - clickedX;
speedY = stage.mouseY - clickedY;
}
speedX *= friction;
speedY *= friction;
// saber el tamaño actual del mapa en este punto.
that.map.x += speedX;
that.map.y += speedY;
console.log(that.map.y);
console.log(that.map.x);
clickedX = stage.mouseX;
clickedY = stage.mouseY;
//
}
function resetMap()
{
that.map.x = mapOriginalX;
that.map.y = mapOriginalY;
that.map.scaleX = that.map.scaleY = 1;
}
function zoomMap(e) //control visual
{
if (e.currentTarget == that.plusButton)
scaleMap(-0.1);
if (e.currentTarget == that.minusButton)
scaleMap(0.1);
}
function moveMap(e) //control visual
{
if (e.currentTarget == that.upButton)
speedY -= mapNudge;
else if (e.currentTarget == that.rightButton)
speedX += mapNudge;
else if (e.currentTarget == that.downButton)
speedY += mapNudge;
else if (e.currentTarget == that.leftButton)
speedX -= mapNudge;
}
function scaleMap(amount)
{
var map = that.map; // we will scale de map so this goes first.
map.scaleX -= amount; // same as map.scaleX = map.scaleX - amount
map.scaleY = map.scaleX;
if (map.scaleX < minScale)
map.scaleX = map.scaleY = minScale;
else if (map.scaleX > maxScale)
map.scaleX = map.scaleY = maxScale;
}
// listeners
this.map.on("mousedown", mouseDown.bind(this));
this.resetButton.on("click", resetMap.bind(this));
this.plusButton.on("click", zoomMap.bind(this));
this.minusButton.on("click", zoomMap.bind(this));
this.upButton.on("click", moveMap.bind(this));
this.rightButton.on("click", moveMap.bind(this));
this.downButton.on("click", moveMap.bind(this));
this.leftButton.on("click", moveMap.bind(this));
stage.on("stagemouseup", stageMouseUp.bind(this));
document.getElementById('canvas').addEventListener('mousewheel', onMouseWheel.bind(this));
document.getElementById('canvas').addEventListener('DOMMouseScroll', onMouseWheel.bind(this));
createjs.Ticker.addEventListener("tick", update.bind(this));
resetMap();
One trick I usually use is to create a "fence" procedure that checks bounds and corrects them. It will take some setup though.
To use this method, first set up these variables based on your own scene. Perhaps this is what you meant by defining a "second stage?"
var stageLeft = 0;
var stageRight = 500;
var stageTop = 0;
var stageBottom = 500;
this.map.setBounds(0,0,1462, 1047); // Set the values to match your map
var mapBounds = this.map.getBounds();
Then, add this procedure, or a variation of it based on how your map coordinates are set.
// procedure to correct the map x/y to fit the stage
function fenceMap() {
var map = that.map;
var ptTopLeft = map.localToGlobal(mapBounds.x,mapBounds.y);
var ptBotRight = map.localToGlobal(mapBounds.width,mapBounds.height);
if ((ptBotRight.x - ptTopLeft.x) > (stageRight-stageLeft)) {
if (ptTopLeft.x > stageLeft) {
map.x -= ptTopLeft.x - stageLeft;
speedX = 0;
} else if (ptBotRight.x < stageRight) {
map.x -= ptBotRight.x - stageRight;
speedX = 0;
}
}
if ((ptBotRight.y - ptTopLeft.y) > (stageBottom-stageTop)) {
if (ptTopLeft.y > stageTop) {
map.y -= ptTopLeft.y - stageTop;
speedY = 0;
} else if (ptBotRight.y < stageBottom) {
map.y -= ptBotRight.y - stageBottom;
speedY = 0;
}
}
}
Then, just add to the end of your update(), zoomMap(), moveMap(), and scaleMap() functions:
fenceMap();
I made A Maze and Action script 3.0 and everything works except when the player touches the exit box (a movie clip called exit) the maze wont go to my win screen.
If someone could help me that'd be great because this is a final project for school
here's my code
var rightArrow:Boolean = false;
var leftArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;
var speed:int = 5;
stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);
stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);
function stage_onKeyDown(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.RIGHT) rightArrow = true;
if(event.keyCode == Keyboard.LEFT) leftArrow = true;
if(event.keyCode == Keyboard.UP) upArrow = true;
if(event.keyCode == Keyboard.DOWN) downArrow = true;
}
function stage_onKeyUp(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.RIGHT) rightArrow = false;
if(event.keyCode == Keyboard.LEFT) leftArrow = false;
if(event.keyCode == Keyboard.UP) upArrow = false;
if(event.keyCode == Keyboard.DOWN) downArrow = false;
}
function stage_onEnterFrame(event:Event):void {
var rect:Rectangle = player.getBounds(this);
var i:int = 0;
var xBump:int = 0;
var yBump:int = 0;
if(rightArrow) {
xBump = speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(rect.right + i, player.y, true)) {
xBump = i - 1;
break;
}
}
}
if(leftArrow) {
xBump = -speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(rect.left - i, player.y, true)) {
xBump = -i + 1;
break;
}
}
}
if(upArrow) {
yBump = -speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(player.x, rect.top - i, true)) {
yBump = -i + 1;
break;
}
}
}
if(downArrow) {
yBump = speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(player.x, rect.bottom + i, true)) {
yBump = i - 1;
break;
}
}
}
player.x += xBump;
player.y += yBump;
}
if(player.hitTestObject(exit)) {
gotoAndStop("win");
}
stop();
Your test:
if(player.hitTestObject(exit)) {
gotoAndStop("win");
}
appears to be outside the function stage_onEnterFrame and is thus only executed once. Make sure the closing brace of the function:
player.x += xBump;
player.y += yBump;
} // this one
Comes after the test, like so:
}
player.x += xBump;
player.y += yBump;
if(player.hitTestObject(exit)) {
gotoAndStop("win");
}
} // closing function here, NOT above
I am looking to control an ROV by using either a PS4 controller or an Xbox 360 controller. I plan to do this by connecting the controller to a computer and then sending that to the ROV. A little background information on the project is, we have the controller up top, which sends it to the computer, and then we will send from the computer to an Arduino on the ROV via Ethernet.
I have learned that this is possible on the PS3 controller by using Processing because another team did it, but I am unfamiliar with that language and don't have a PS3 controller. However, I have a PS4 and Xbox 360 controller.
From what I have researched, SDL could be an option for this, but I am looking for advice from more experienced people than me.
My question got deleted by pissed mods, because it was "unrelated", but I asked the same. Anyway, I implemented my PS4 controller support with SFML like this. Other simple possibility would be SDL. XBox will be the same I guess. Have fun
Here some sample code..
sf::Joystick::update();
// Is joystick #0 connected?
m_bGamepadConnected = sf::Joystick::isConnected(0);
if(!m_bGamepadConnected) {
return;
}
// Does joystick #0 define a X axis?
m_bStickLX = sf::Joystick::hasAxis(0, sf::Joystick::X);
m_bStickLY = sf::Joystick::hasAxis(0, sf::Joystick::Y);
m_bStickRX = sf::Joystick::hasAxis(0, sf::Joystick::Z);
m_bStickRY = sf::Joystick::hasAxis(0, sf::Joystick::R);
m_bStickL2 = sf::Joystick::hasAxis(0, sf::Joystick::U);
m_bStickR2 = sf::Joystick::hasAxis(0, sf::Joystick::V);
m_tJoystick.start(5);
QObject::connect(&m_tJoystick, SIGNAL(timeout() ), this, SLOT(updateGamepad() ) );
And this may help you ..
sf::Joystick::update();
float fStickLX = 0;
float fStickLY = 0;
float fStickRX = 0;
float fStickRY = 0;
float fStickL2 = 0;
float fStickR2 = 0;
// What's the current position of the analog sticks
if(m_bStickLX) {
fStickLX = sf::Joystick::getAxisPosition(0, sf::Joystick::X) / 100;
}
if(m_bStickLY) {
fStickLY = sf::Joystick::getAxisPosition(0, sf::Joystick::Y) / 100;
}
if(m_bStickRX) {
fStickRX = sf::Joystick::getAxisPosition(0, sf::Joystick::Z) / 100;
}
if(m_bStickRY) {
fStickRY = sf::Joystick::getAxisPosition(0, sf::Joystick::R) / 100;
}
// R2 and L2
if(m_bStickL2) {
fStickL2 = sf::Joystick::getAxisPosition(0, sf::Joystick::U) + 100;
fStickL2 /= 200;
}
if(m_bStickR2) {
fStickR2 = sf::Joystick::getAxisPosition(0, sf::Joystick::V) + 100;
fStickR2 /= 200;
}
if(m_fStickLX != 0 || m_fStickLY != 0 || m_fStickRX != 0 || m_fStickRY != 0 || m_fStickL2 != fStickL2 || m_fStickR2 != fStickR2) {
m_bGamepadInUse = true;
} else {
m_bGamepadInUse = false;
}
m_fStickLX = fStickLX;
m_fStickLY = fStickLY;
m_fStickRX = fStickRX;
m_fStickRY = fStickRY;
m_fStickL2 = fStickL2;
m_fStickR2 = fStickR2;
m_bButLPressed = isButtonPressed(0, 0);
m_bButDPressed = isButtonPressed(0, 1);
m_bButRPressed = isButtonPressed(0, 2);
m_bButTPressed = isButtonPressed(0, 3);
//qDebug() << "m_bButDPressed pressed: " << m_bButDPressed;
static bool bArmToggle = false;
if(m_bButDPressed && !bArmToggle) {
m_bDeviceArmed = m_bDeviceArmed ? false : true;
bArmToggle = true;
qDebug() << "Device armed?: " << m_bDeviceArmed;
}
if(bArmToggle && !m_bButDPressed) {
bArmToggle = false;
}